【发布时间】:2021-02-26 09:48:37
【问题描述】:
Ubuntu 20.04.2 LTS
nginx 1.18.0
php 7.4.15
我有一个多租户 Laravel 应用程序的以下配置
server {
server_name console.example.com;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /certs/example.com.crt;
ssl_certificate_key /certs/example.com.key;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m; # about 40000 sessions
ssl_session_tickets off;
# modern configuration
ssl_protocols TLSv1.3;
ssl_prefer_server_ciphers off;
# HSTS (ngx_http_headers_module is required) (63072000 seconds)
add_header Strict-Transport-Security "max-age=63072000" always;
# OCSP stapling
ssl_stapling on;
ssl_stapling_verify on;
# verify chain of trust of OCSP response using Root CA and Intermediate certs
ssl_trusted_certificate /certs/example.com.bundle;
root /home/example/example-console/current/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
# client_max_body_size 200m;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [\S-/]+/upload$ {
client_max_body_size 200m;
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
在当前状态下,我收到 413 Request Entity Too Large 错误。
我使用https://nginx.viraptor.info/ 测试匹配,https://console.example.com/foo/upload 和 https://console.example.com/foo/bar/upload 都显示为匹配
当我取消注释 server 块中的 client_max_body_size 200m; 时,它按预期工作,所以我知道 PHP 不会妨碍您。
【问题讨论】: