提高上傳檔案大小上限 Nextcloud 默認上傳的最大檔案大小為 512MB ,如果想提高則須修改以下內容。 (此修改適用於 TrueNAS CORE Jail 的 Nextcloud,其他系統的配置檔位置則會有些許出入)
修改 /usr/local/etc/php/php.truenas.ini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [PHP] memory_limit =1024 Mpost_max_size =20 Gupload_max_filesize =20 Gmax_execution_time = 3600 [opcache] opcache.enable =1 opcache.enable_cli =1 opcache.memory_consumption =2048 opcache.interned_strings_buffer =16 opcache.max_accelerated_files =30000 opcache.revalidate_freq =1 opcache.save_comments =1 opcache.validate_timestamps = 0 opcache.revalidate_freq = 60 opcache.max_file_size = 0 [apcu] apc.enable_cli =1
memory_limit
: 提高到 1G 加快網頁載入速度 (預設值 125MB)post_max_size
, upload_max_filesize
: 調整為 20G 表示最大上傳單檔案大小為 20Gmax_execution_time
: 延長 php 的執行時間避免檔案還沒上傳完就超時 (504 塊組裝錯誤 就是因為這個)
修改 /usr/local/etc/nginx/nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 load_module /usr/local/libexec/nginx/ngx_mail_module.so; load_module /usr/local/libexec/nginx/ngx_stream_module.so; user www; worker_processes auto; pid /var/run/nginx.pid; events { use kqueue; worker_connections 1024; multi_accept on; } http { # Basic settings # ---------- sendfile on; tcp_nopush on; tcp_nodelay on; reset_timedout_connection on; keepalive_timeout 65; keepalive_requests 1000; types_hash_max_size 2048; server_tokens off; send_timeout 3600; #30; server_names_hash_max_size 4096; fastcgi_connect_timeout 3600s; fastcgi_send_timeout 3600s; fastcgi_read_timeout 3600s; # Common limits # ---------- client_max_body_size 100m; # upload size client_body_buffer_size 1m; client_header_timeout 3600; #3m; client_body_timeout 3600; #3m; client_body_temp_path /var/tmp/nginx/client_body_temp; proxy_connect_timeout 3600; #5; proxy_send_timeout 3600; #10; proxy_read_timeout 3600; #10; proxy_buffer_size 4k; proxy_buffers 8 16k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_temp_path /var/tmp/nginx/proxy_temp; include mime.types; default_type application/octet-stream; # Logs format # ---------- log_format main '$remote_addr - $host [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' 'rt=$request_time ut=$upstream_response_time ' 'cs=$upstream_cache_status'; log_format cache '$remote_addr - $host [$time_local] "$request" $status ' '$body_bytes_sent "$http_referer" ' 'rt=$request_time ut=$upstream_response_time ' 'cs=$upstream_cache_status'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log warn; # GZip config # ---------- gzip on; gzip_static on; gzip_types text/plain text/css text/javascript text/xml application/x-javascript application/javascript application/xml application/json image/x-icon; gzip_comp_level 9; gzip_buffers 16 8k; gzip_proxied expired no-cache no-store private auth; gzip_min_length 1000; gzip_disable "msie6" gzip_vary on; # Cache config # ---------- proxy_cache_valid 1m; # Virtual host config # ---------- # SSL # ---------- ssl_certificate /usr/local/etc/letsencrypt/live/truenas/fullchain.pem; ssl_certificate_key /usr/local/etc/letsencrypt/live/truenas/privkey.pem; # Verify chain of trust of OCSP response using Root CA and Intermediate certs ssl_trusted_certificate /usr/local/etc/letsencrypt/live/truenas/chain.pem; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; # about 40000 sessions ssl_session_tickets off; # intermediate configuration # Keep only TLS 1.2 (+ TLS 1.3) ssl_protocols TLSv1.2 TLSv1.3; # Use only strong ciphers ssl_ciphers TLS-CHACHA20-POLY1305-SHA256:TLS-AES-256-GCM-SHA384:TLS-AES-128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; # Use more secure ECDH Curve ssl_ecdh_curve X25519:P-521:P-384:P-256; # Defend against the BEAST attack ssl_prefer_server_ciphers off; # OCSP Stapling ssl_stapling on; ssl_stapling_verify on; include /usr/local/etc/nginx/conf.d/*.conf; }
把以下 timeout 都提高到 3600s (解決 504 塊組裝錯誤) 如果有添加反向代理的話也需要把 timeout 都調到同樣數值。
fastcgi_connect_timeout fastcgi_send_timeout fastcgi_read_timeout
send_timeout client_header_timeout client_body_timeout
proxy_connect_timeout proxy_send_timeout proxy_read_timeout
修改上傳塊大小 Nextcloud 預設的上傳塊大小為 10MB,如果網路頻寬足夠則可加大塊大小以提高性能。
使用以下 occ 命令提高到 20MB
1 occ config:app:set files max_chunk_size --value 20971520
不建議設置為 0 (不分塊),從外網上傳檔案常常會失敗
可參考以下連結https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/big_file_upload_configuration.html#adjust-chunk-size-on-nextcloud-side