18

Rails 3.2.3、Ruby 1.9.3、および Nginx モジュールを備えた Phusion Passenger を使用する Rails アプリがあります。アプリのユーザーは大きなファイルをアップロードする必要があります。nginx.conf (以下) のロケーション ブロックにディレクティブを追加し、client_max_body_size 500M;Ctrl-C を使用して nginx を停止し、nginx を再起動して、nginx を停止および開始しましpassenger startた。ただし、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 Error 413http://forum.slicehost.com/index.php?p=/discussion/1714/nginx-413-when-uploading-file-1mb-or-larger/p1から判断すると、client_max_body_size指定してみてください疑わしいように見えますが、おそらくサーバーセクションでのみ、1回だけです。

また、別の回答で述べたように、値として「4g」が必要だと思います。

于 2012-05-14T17:17:28.357 に答える
0

client_max_body_size 10m; 「;」で私のために働きます そして、NginxとUnicorn、またはApacheを再起動します...など

@MaffooClock が言うように、http ブロック内。

于 2016-07-28T19:44:39.203 に答える
0

これはただの推測です。私は Rails も Ruby も nginx も知らないので、自分の考えが当てはまるかどうかはわかりませんが、とにかくここにあるので、役立つかもしれません...

ファイルがどのような方法で転送されているか確認しましたか? あなたの問題は、私の Ajax リクエストが神秘的に失敗した状況を思い出させます。いくつかの調査の後、すべてのリクエストが GET 経由で送信されたことがわかりました (これはそもそも間違った方法でした)。それを POST に変更すると、問題が解決しました。

そこにファイルを送信しているので、まったく別のものかもしれません (サイズが 2KiB 程度のデータがありました)。

于 2012-05-11T16:32:42.453 に答える