我有一个使用Rails 3.2.3,Ruby 1.9.3和带有Nginx模块的Phusion Passenger的rails应用程序。 App用户需要上传大文件。我将指令client_max_body_size 500M;
添加到nginx.conf(下面)中的位置块,并通过使用Ctrl-C停止nginx并使passenger start
重新启动nginx来停止并启动nginx。但是,当我尝试上传127 MB的文件时,我收到错误“413 Request Entity Too Large”。有人能让我知道我在忽视什么吗?
谢谢,
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
passenger_root /Users/mcmahling/.rvm/gems/ruby-1.9.3-p125/gems/passenger-3.0.12;
passenger_ruby /Users/mcmahling/.rvm/wrappers/ruby-1.9.3-p125/ruby;
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 165;
#gzip on;
server {
listen 80;
server_name localhost;
client_max_body_size 4G;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
client_max_body_size 4G;
client_body_buffer_size 128k;
client_body_temp_path /usr/local/nginx/client_body_temp;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
答案 0 :(得分:26)
将client_max_body_size 4G;
更改为服务器块内的4g;
或500m;
答案 1 :(得分:4)
从Nginx Error 413和http://forum.slicehost.com/index.php?p=/discussion/1714/nginx-413-when-uploading-file-1mb-or-larger/p1判断,您可能会尝试只在一次指定client_max_body_size
,可能只在服务器部分指定,尽管这看起来很可疑。
另外,正如另一个回复中提到的,我认为你想要'4g'作为价值。
答案 2 :(得分:0)
这只是一个疯狂的猜测,因为我既不知道Rails,Ruby也不知道nginx,我无法确定我的想法是否适用,但不管怎么说,无论如何,也许它有帮助......
您是否检查了文件的传输方式?你的问题让我想起了我的Ajax请求失败的情况。经过一些研究,我发现了所有通过GET发送的请求(这是首先做错的方法)。将其更改为POST解决了我的问题。
由于您在那里发送文件,可能是完全不同的事情(我的数据大小约为2KiB左右)。
答案 3 :(得分:0)
client_max_body_size 10m; 适用于我,有';'在和,并重新启动Nginx和Unicorn,或apache ......等
就像@MaffooClock所说,在http块内。