"413 Request Entity Too Large" Error Rails 3.2 Passenger Phusion
Asked Answered
U

4

18

I have a rails app using Rails 3.2.3, Ruby 1.9.3, and Phusion Passenger with the Nginx module. App users need to upload large files. I added the directive client_max_body_size 500M; to the location block in the nginx.conf (below) and stopped and started nginx through using Ctrl-C to stop nginx and passenger start to restart nginx. However, when I try to upload a file that is 127 mb, I get the error "413 Request Entity Too Large". Can someone let me know what I am overlooking?

Thanks,

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

}
Unbated answered 4/5, 2012 at 19:16 Comment(1)
R
27

Change client_max_body_size 4G; to 4g; or 500m; insde the server block

Recrimination answered 5/5, 2012 at 1:24 Comment(8)
Thank you for the answer. I changed the value to gb,GB,mb, and MB, respectively; however, I receive an error that those values are invalid.Unbated
It should just be 4g or 500m.Wainscot
I had the same problem. Added client_max_body_size 4g; inside the http block, problem solved.Evert
In case you have multiple config files laying around that might also be setting this parameter, use the following find all occurrences of it: sudo grep -R 'client_max_body_size' ./*Arachnoid
Thanks, worked. I put client_max_body_size 4g; in the server block. Don't forget to restart nginx. Also, if you have PHP, you'll have to set the client_max_body_size there too.Unitarian
Maybe I misunderstand something here, but only with allowing bigger files the problem doesn't go away, does it? If I try to upload 1001mb, then the problem will come again, doesn't it?Kweisui
Can someone explain what a g and a m are? Since you're increasing the size from 4g to 500m I wouldn't imagine that means it's chaning from 4gb to 500mb as that's obviously decreasing the size.Gateshead
@MatthewClark Is it important to add client_max_body_size 4g; in which part of the config file? I've added it but I have still the same problem! I'm using Rails with Nginx on our own server.Perrins
D
4

Judging from Nginx Error 413 and http://forum.slicehost.com/index.php?p=/discussion/1714/nginx-413-when-uploading-file-1mb-or-larger/p1, you might try having client_max_body_size specified just a single time, possibly only in the server section, although that seems dubious.

Also, as mentioned in another response, I think you want '4g' as the value.

Disharmony answered 14/5, 2012 at 17:17 Comment(0)
I
0

This is just a wild guess, and since I know neither Rails, Ruby nor nginx, I can not really find out if my idea applies, but here is it anyway, maybe it helps...

Did you check by what method the files are transfered? Your problem reminds me of a situation where my Ajax-requests failed mystically. After some research, I found out all requests where sent via GET (which was the wrong way to do it in the first place). Changing it to POST solved my problem then.

Since you are sending files there, it might be a totally different thing (I had data about 2KiB in size or so).

Incretion answered 11/5, 2012 at 16:32 Comment(0)
F
0

client_max_body_size 10m; works for me, with ';' at the and, and restart Nginx and Unicorn, or apache...etc

Like @MaffooClock says, inside the http block.

Flowerer answered 28/7, 2016 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.