Php Nginx错误413
当我试图上传一个文件到我的站点时,我得到了Nginx“413请求实体太大”错误,但是在我的Nginx.conf文件中,我已经明确说明了最大大小目前约为250MB,并在php.ini中更改了最大文件大小(是的,我重新启动了进程)。错误日志告诉我: 2010/12/06 04:15:06[错误]20124#0: *11975客户端打算发送太大的正文:1144149字节,客户端: 60.228.229.238,服务器:www.x.com,请求:“发布 /上载HTTP/1.1”,主机: “x.com”,推荐人: "http://x.com/" 据我所知,1144149字节不是250MB。。。 这里有我遗漏的东西吗 以下是基本Nginx配置:Php Nginx错误413,php,file-upload,nginx,Php,File Upload,Nginx,当我试图上传一个文件到我的站点时,我得到了Nginx“413请求实体太大”错误,但是在我的Nginx.conf文件中,我已经明确说明了最大大小目前约为250MB,并在php.ini中更改了最大文件大小(是的,我重新启动了进程)。错误日志告诉我: 2010/12/06 04:15:06[错误]20124#0: *11975客户端打算发送太大的正文:1144149字节,客户端: 60.228.229.238,服务器:www.x.com,请求:“发布 /上载HTTP/1.1”,主机: “x.com”,
user nginx;
worker_processes 8;
worker_rlimit_nofile 100000;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
client_max_body_size 300M;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
gzip on;
gzip_static on;
gzip_comp_level 5;
gzip_min_length 1024;
keepalive_timeout 300;
limit_zone myzone $binary_remote_addr 10m;
# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/sites/*;
}
以及该站点的vhost:
server {
listen 80;
server_name www.x.com x.com;
access_log /var/log/nginx/x.com-access.log;
location / {
index index.html index.htm index.php;
root /var/www/x.com;
if (!-e $request_filename) {
rewrite ^/([a-z,0-9]+)$ /$1.php last;
rewrite ^/file/(.*)$ /file.php?file=$1;
}
location ~ /engine/.*\.php$ {
return 404;
}
location ~ ^/([a-z,0-9]+)\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
不知道您的nginx构建版本以及构建时使用的模块会使这一点变得困难,但请尝试以下方法:
我还补充说,您可以在*.php位置处理程序中定义它
location ~ ^/([a-z,0-9]+)\.php$ {
作为级联级别中的“较低”一级,这将是一种很容易看出问题是否来自nginx配置或模块的方法
它肯定不是来自PHP,因为413错误“body too large”实际上是一个NGinx错误。我的设置是:
php.ini
...
upload_max_filesize = 8M
...
...
upload_max_filesize = 8M
...
nginx.conf
...
client_max_body_size 8m;
...
...
client_max_body_size 80m;
...
nginx在上传时显示错误413
然后我有了一个想法:我不会让nginx显示错误413,client_max_body_size设置为大于upload_max_filesize的值,因此:
php.ini
...
upload_max_filesize = 8M
...
...
upload_max_filesize = 8M
...
nginx.conf
...
client_max_body_size 8m;
...
...
client_max_body_size 80m;
...
发生了什么事
当上传小于80MB的文件时,nginx不会显示错误413,但如果文件大小达到8MB,PHP会显示错误
这解决了我的问题,但如果有人上传大于80MB的文件,则会发生错误413,nginx规则。您可能应该引用您更改的nginx配置设置我添加了客户端\u max\u body\u size 64m;进入conf的http{}部分,重新启动,它工作了!谢谢这为我解决了问题。我认为我的节点服务器上的主体解析器是问题所在,但完全忘记了在nginx中设置这一行。我不知道为什么我在这个答案上被否决了?想解释一下吗?