当我试图上传一个文件到我的站点时,我得到了Nginx "413请求实体太大“的错误,但是在我的nginx.conf文件中,我已经明确声明了当前最大文件大小约为250 my,并在php.ini中更改了最大文件大小(是的,我重新启动了进程)。错误日志提供了以下内容:
2010/12/06 04:15:06错误20124#0:*11975客户机打算发送太大的主体: 1144149字节,客户机: 60.228.229.238,服务器: www.x.com,请求:"POST /upload HTTP/1.1",主机:"x.com",引用者:"http://x.com/“
据我所知,1144149字节不是250‘t.这里有什么东西我遗漏了吗?
下面是基本的Nginx配置:
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;
}
}
}发布于 2011-02-22 17:18:06
不知道nginx构建的版本以及它是用什么模块构建的,这使得这很困难,但是请尝试以下几点:
。
发布于 2012-03-14 19:03:10
我的设计是:
php.ini
...
upload_max_filesize = 8M
...nginx.conf
...
client_max_body_size 8m;
...nginx在上传时显示了这个错误413。
然后我有了一个想法:我不会让nginx显示错误413,client_max_body_size设置为大于upload_max_filesize的值,因此:
php.ini
...
upload_max_filesize = 8M
...nginx.conf
...
client_max_body_size 80m;
...发生了什么?
当您上传小于80 8MB时,nginx将不会显示错误413,但是如果文件高达8MB,PHP将显示错误。
这解决了我的问题,但如果有人上传的文件大于80 my错误413发生,nginx规则。
发布于 2012-02-17 13:56:01
我还补充说,可以在*.php位置处理程序中定义它。
location ~ ^/([a-z,0-9]+)\.php$ {作为级联级的“较低”级别,查看问题是否来自nginx配置或模块是一种简单的方法。
它肯定不是来自PHP,因为413错误“主体太大”实际上是一个NGinx错误。
https://stackoverflow.com/questions/4365821
复制相似问题