首页 云计算文章正文

Nextcloud更新索引、伪静态、性能优化

云计算 2024年11月26日 12:06 1 admin

NexTCLoud更新索引、伪静态、性能优化

2023-07-12 分类:主机教程 阅读() 评论(0)

一、直接上传或同步文件服务器后,更新文件索引

#扫描所有用户的所有文件,并更新索引。

sudo -u www php occ files:scan --All

注意 PHP 和 OCC 文件路径,也可以直接写绝对路径:

sudo -u www /usr/local/php8.0/bin/php /hoMe/wwwroot/www.example.com/occ files:scan --all

#只扫描指定用户或者指定文件夹,并更新索引。

列出所有用户:

sudo -u www php occ user:list

只扫描 test 用户的文件:

sudo -u www php occ files:scan test

扫描用户的指定目录

sudo -u www php occ files:scan --path="/test/files/download"

二、Nextcloud 伪静态规则

gzIP on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
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;

# HTTP response headers borrowed from Nextcloud `.htaccess`
add_header Referrer-Policy                      "no-referrer"   always;
add_header X-Content-Type-Options               "nosniFF"       always;
add_header X-Download-Options                   "noopen"        always;
add_header X-Frame-Options                      "SAMEORIGIN"    always;
add_header X-Permitted-Cross-Domain-Policies    "none"          always;
add_header X-Robots-Tag                         "none"          always;
add_header X-XSS-Protection                     "1; mode=bloCK" always;

# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;

#原有的基础上添加 /index.php$request_uri;
index index.php index.html /index.php$request_uri;

# Rule borrowed from `.htaccess` to handle Microsoft DAV clients
location = / {
    if ( $http_user_agent ~ ^DavClnt ) {
        return 302 /remote.php/webdav/$is_args$args;
    }
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

location ^~ /.well-known {
    # The rules in this block are an adaptation of the rules
    # in `.htaccess` that concern `/.well-known`.

    location = /.well-known/carddav { return 301 /remote.php/dav/; }
    location = /.well-known/caldav  { return 301 /remote.php/dav/; }

    location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
    location /.well-known/pki-validation    { try_files $uri $uri/ =404; }

    # Let Nextcloud's API for `/.well-known` URIs handle all other
    # requests by passing them to the front-end controller.
    return 301 /index.php$request_uri;
}

# Rules borrowed from `.htaccess` to hide certain paths from clients
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console)                { return 404; }


location ~ \.php(?:$|/) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    set $path_info $fastcgi_path_info;

    try_files $fastcgi_script_name =404;

    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param HTTPS on;

    fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice

    fastcgi_param front_controller_active true;     # Enable pretty urls
    fastcgi_pass unix:/tmp/php-cgi.sock;   #自行修改为对应路径
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
}

location ~ \.(?:css|js|svg|gif|png|jpg|ico)$ {
    try_files $uri /index.php$request_uri;
    expires 6M;         # Cache-Control policy borrowed from `.htaccess`
    access_log off;     # Optional: Don't log access to assets
}

location ~ \.woff2?$ {
    try_files $uri /index.php$request_uri;
    expires 7d;         # Cache-Control policy borrowed from `.htaccess`
    access_log off;     # Optional: Don't log access to assets
}

# Rule borrowed from `.htaccess`
location /remote {
    return 301 /remote.php$request_uri;
}

location / {
    try_files $uri $uri/ /index.php$request_uri;
}

三:解决423 locked

#临时解决方法

进入维护模式:

sudo -u www php occ maintenance:mode --on

清空 oc_file_locks 表:

delete * from oc_file_locks;
或者
truncate table oc_file_locks;

退出维护模式:

sudo -u www php occ maintenance:mode --off

#彻底解决方法

参考官网:https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/caching_configuration.html?highlight=cache

为 Nextcloud 配置 Redis 缓存,在 config/config.php 文件中添加以下配置:

'memcache.locking' => '\OC\Memcache\Redis',
'redis' => [
  'host'      => '127.0.0.1',
  'port'      => 6379,
  'user'          => 'Redis用户',
  'password'      => 'Redis密码',
  'dbindex'       => 0,
  'Timeout'       => 1.5,
  'read_timeout'  => 1.5,
]

四:性能优化

#内存缓存优化

APCu(官方推荐):

安装PHP的APCu扩展,在 config/config.php 文件中添加以下配置:

'memcache.local' => '\OC\Memcache\APCu',

Redis(官方说多服务器可能导致问题,单机速度不如APCu):

'memcache.local' => '\OC\Memcache\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => [
  'host'      => '127.0.0.1',
  'port'      => 6379,
  'user'          => 'Redis用户名',
  'password'      => 'Redis密码',
  'dbindex'       => 0,
  'timeout'       => 1.5,
  'read_timeout'  => 1.5,
]

#PHP优化

upload_max_filesize 5G
post_max_size 5g
max_input_time 3600
max_execution_time 3600
memory_limit = 512M
output_buffering = 0
upload_tmp_dir = /dev/shm/client_body_temp

#NGINX优化

client_max_body_size 5G
fastcgi_read_timeout 3600
client_body_temp_path /dev/shm/client_body_temp

临时文件目录设置为内存时,推荐大内存服务器,务必配置 SWAP。

#如果 Nextcloud 位于 cdn 或者负载均衡后

有前端权限:建议关闭proxy_buffering或增加proxy_max_temp_file_size的值。

无前端权限:add_header X-Accel-Buffering no;

#高上传带宽环境中提高上传性能,调整 Nextcloud 端的块大小(默认为10M)

sudo -u www php occ config:app:set files max_chunk_size --value 20971520
AD: 一个萌萌哒广告位】 FUNCDN真正亚洲优化CDN,电信CN2 / 联通CU / 移动CM A+级频宽高速接驳。 未经允许不得转载: 主机资讯-vps商家前沿资讯 » Nextcloud更新索引、伪静态、性能优化 Nextcloud Nextcloud伪静态规则 Nextcloud性能优化

主机资讯

主机资讯是一个致力于收集和发布免费VPS,免费域名,免费空间,免费虚拟主机,免费CDN,免费SSL,免费DNS,免费云主机,便宜VPS,特价VPS,美国免费空间,香港免费空间,香港空间,免费主机空间,免费网站空间,免费VPS推荐,免费空间推荐,便宜服务器,搬瓦工,VPS优惠等相关资源的聚合网站,是目前国内最好的了解前沿主机资讯的平台之一。 上一篇
DigitaLVirt:23元/月/2核/1G内存/10G NVMe硬盘/1T流量/300Mbps端口/KVM/洛杉矶/AS9929
下一篇
Misaka:$21/月/1核/1G内存/16G SSD硬盘/716G流量/1Gbps端口/台北/Chief

相关推荐

  • Nextcloud教程篇:Tampermonkey油猴脚本云同步
  • CloudCone存储VPS一键DD安装飞牛NAS系统
  • 飞致云:MaxKB开源LLM大语言模型知识库问答系统
  • CentOS 7生命周期结束(EOL)YUM源处理
  • PHP8 Composer Segmentation fault报错解决方法
  • VmShell服务器无法自定义DNS解决方法
  • 分享两个可以解析App Store直接下载IPA文件的网站
  • Migration backend is currently not available for this VPS. (73.152)搬瓦工机房迁移失败解决方法

亿网科技新闻资讯门户 Copyright 2008-2025 南京爱亿网络科技有限公司 苏ICP备14058022号-4 edns.com INC, All Rights Reserved