18

我有一个使用 Rails 3.2.3、Ruby 1.9.3 和带有 Nginx 模块的 Phusion Passenger 的 rails 应用程序。应用用户需要上传大文件。我将指令添加client_max_body_size 500M;到 nginx.conf(如下)中的位置块,并通过使用 Ctrl-C 停止和重新启动 nginx 来停止和passenger start启动 nginx。但是,当我尝试上传 127 mb 的文件时,我收到错误“413 Request Entity Too Large”。有人可以让我知道我忽略了什么吗?

谢谢,

我的 nginx.conf

#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;
    #    }
    #}

}
4

4 回答 4

27

更改client_max_body_size 4G;4g;插入500m;服务器块

于 2012-05-05T01:24:55.143 回答
4

Nginx 错误 413http://forum.slicehost.com/index.php?p=/discussion/1714/nginx-413-when-uploading-file-1mb-or-larger/p1来看,您可能会尝试client_max_body_size指定只是一次,可能只在服务器部分,虽然这看起来很可疑。

另外,正如另一个回复中提到的,我认为您希望将“4g”作为值。

于 2012-05-14T17:17:28.357 回答
0

这只是一个疯狂的猜测,由于我既不了解 Rails、Ruby 也不了解 nginx,因此我无法确定我的想法是否适用,但无论如何,这就是它,也许它会有所帮助......

您是否检查过文件是通过什么方式传输的?您的问题让我想起了我的 Ajax 请求神秘地失败的情况。经过一番研究,我发现了所有通过 GET 发送的请求(这首先是错误的方法)。然后将其更改为 POST 解决了我的问题。

由于您在那里发送文件,这可能是完全不同的事情(我有大约 2KiB 大小的数据)。

于 2012-05-11T16:32:42.453 回答
0

client_max_body_size 10m;为我工作,带有';' 在and处,重启Nginx和Unicorn,或者apache...等

就像@MaffooClock 所说,在 http 块内。

于 2016-07-28T19:44:39.203 回答