当前位置:   article > 正文

宝塔面板下nextcloud完美优化配置_nextcloud页面响应提速

nextcloud页面响应提速

宝塔面板下nextcloud完美优化配置

 

一、性能优化

 

Nextcloud由于各种原因,默认安装后,任何页面加载时间都过于缓慢。之前的文章有介绍到使用PHP的APCu模块以提升缓存性能,这里再介绍使用Memcached提高Nextcloud的性能。

Nextcloud支持多个不同类型的缓存后端,所以可以同时启用本地缓存(APCu)和分布式缓存(Memcached、Redis),官方推荐的组合是APCu+Redis

分布式缓存选择Memcached、Redis其中一种启用即可,无需两者都启用

宝塔面板很方便的可以安装php的Memcached和Redis模块(注意是memcached,非memcache),这里我以APCu+Memcached为例

 

安装完毕后,打开/www/wwwroot/你的nextcloud目录/config/config.php,在其尾部添加以下代码

第1行为指定本地缓存为APCu,第2、3行为指定分布式缓存为Memcached

  1. 'memcache.local' => '\OC\Memcache\APCu',
  2. 'memcache.distributed' => '\OC\Memcache\Memcached',
  3. 'memcached_servers' => array(
  4. array('localhost', 11211),
  5. )

如图,注意分号,保存即可

 

Redis则需要稍微修改一下配置

  1. 'memcache.local' => '\OC\Memcache\APCu',
  2. 'memcache.distributed' => '\OC\Memcache\Redis',
  3. 'redis' => array(
  4. 'host' => 'localhost',
  5. 'port' => 6379,
  6. )

二、Nginx配置

这一步最为蛋疼,官方给出的Nginx配置示例,有些是可以参考的,有些挪到宝塔上来则会有各种奇奇怪怪的问题,所以需要针对宝塔修改nextcloud下Nginx的配置。

经过几天的折腾,这部分终于也解决的差不多了。分享一下我的Nginx配置,为方便理解和阅读,我已在配置文件中加入一些注释,可以根据情况修改一下即可。

  1. server
  2. {
  3. #基础配置,这些可以照搬宝塔的配置
  4. listen 80;
  5. listen 443 ssl http2;
  6. server_name file.bugxia.com;
  7. index index.php index.html index.htm default.php default.htm default.html;
  8. root /www/wwwroot/file.bugxia.com;
  9. client_max_body_size 10G;
  10. fastcgi_buffers 64 4K;
  11. gzip on;
  12. gzip_vary on;
  13. gzip_comp_level 4;
  14. gzip_min_length 256;
  15. gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
  16. gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
  17. #nextcloud包含了403404的错误页面
  18. error_page 403 /core/templates/403.php;
  19. error_page 404 /core/templates/404.php;
  20. #防止一些HTTP响应头引起的安全隐患
  21. add_header Strict-Transport-Security 'max-age=15552000';
  22. add_header X-Content-Type-Options 'nosniff';
  23. add_header X-Robots-Tag 'none';
  24. add_header X-Frame-Options 'SAMEORIGIN';
  25. add_header X-Download-Options 'noopen';
  26. add_header X-Permitted-Cross-Domain-Policies 'none';
  27. add_header X-XSS-Protection '1;mode=block';
  28. add_header Referrer-Policy "no-referrer";
  29. #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
  30. #error_page 404/404.html;
  31. ssl_certificate /www/server/panel/vhost/cert/file.bugxia.com/fullchain.pem;
  32. ssl_certificate_key /www/server/panel/vhost/cert/file.bugxia.com/privkey.pem;
  33. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  34. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
  35. ssl_prefer_server_ciphers on;
  36. ssl_session_cache shared:SSL:10m;
  37. ssl_session_timeout 10m;
  38. error_page 497 https://$host$request_uri;
  39. #SSL-END
  40. #PHP-INFO-START PHP引用配置,可以注释或修改
  41. #include enable-php-74.conf;
  42. #PHP-INFO-END
  43. #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
  44. include /www/server/panel/vhost/rewrite/file.bugxia.com.conf;
  45. #REWRITE-END
  46. location = /.well-known/carddav {
  47. return 301 $scheme://$host:$server_port/remote.php/dav;
  48. }
  49. location = /.well-known/caldav {
  50. return 301 $scheme://$host:$server_port/remote.php/dav;
  51. }
  52. location / {
  53. rewrite ^ /index.php;
  54. }
  55. #Let's Encrypt 证书续期验证目录
  56. location ~ \.well-known{
  57. allow all;
  58. }
  59. #nextcloud一些关键目录的权限设置
  60. location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
  61. deny all;
  62. }
  63. location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
  64. deny all;
  65. }
  66. location ~ [^/]\.php(/|$) {
  67. fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
  68. set $path_info $fastcgi_path_info;
  69. try_files $fastcgi_script_name =404;
  70. include fastcgi_params;
  71. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  72. fastcgi_param PATH_INFO $path_info;
  73. fastcgi_param HTTPS on;
  74. fastcgi_param modHeadersAvailable true;
  75. #宝塔默认是include调用PHP相关配置,这里稍稍修改了一下,注意php版本 #加入了front_controller_active这项参数以隐藏页面URL中的index.php
  76. fastcgi_param front_controller_active true;
  77. fastcgi_pass unix:/tmp/php-cgi-74.sock;
  78. fastcgi_intercept_errors on;
  79. fastcgi_request_buffering off;
  80. include fastcgi.conf;
  81. include pathinfo.conf;
  82. }
  83. location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
  84. try_files $uri/ =404;
  85. index index.php;
  86. }
  87. location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
  88. try_files $uri /index.php$request_uri;
  89. add_header Cache-Control "public, max-age=15778463";
  90. add_header Referrer-Policy "no-referrer" always;
  91. add_header X-Content-Type-Options "nosniff" always;
  92. add_header X-Download-Options "noopen" always;
  93. add_header X-Frame-Options "SAMEORIGIN" always;
  94. add_header X-Permitted-Cross-Domain-Policies "none" always;
  95. add_header X-Robots-Tag "none" always;
  96. add_header X-XSS-Protection "1; mode=block" always;
  97. access_log off;
  98. }
  99. location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
  100. try_files $uri /index.php$request_uri;
  101. access_log off;
  102. }
  103. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  104. {
  105. expires 30d;
  106. error_log off;
  107. access_log /dev/null;
  108. }
  109. location ~ .*\.(js|css)?$
  110. {
  111. expires 12h;
  112. error_log off;
  113. access_log /dev/null;
  114. }
  115. }

参考:

https://docs.nextcloud.com/server/13/admin_manual/configuration_server/caching_configuration.html

https://serverfault.com/questions/845696/nginx-rewrite-nextcloud-index-php-in-url

 

 
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/1002866
推荐阅读
相关标签
  

闽ICP备14008679号