Upstream too big - nginx + codeigniter

Add this to your http {} of the nginx.conf file normally located at /etc/nginx/nginx.conf:

proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;

Then add this to your php location block, this will be located in your vhost file look for the block that begins with location ~ .php$ {

fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;

I have proven that this is also sent when an invalid header is transmitted. Invalid characters or formatting of the HTTP headers, cookie expiration set back by more than a month, etc will all cause: upstream sent too big header while reading response header from upstream


Modify your nginx configuration and change/set the following directives:

    proxy_buffer_size   128k;
    proxy_buffers   4 256k;
    proxy_busy_buffers_size   256k;

using nginx + fcgiwrap + request too long

I had the same problem because I use a nginx + fcgiwrap configuration:

location ~ ^.*\.cgi$ {
    fastcgi_pass  unix:/var/run/fcgiwrap.sock;
    fastcgi_index index.cgi;
    fastcgi_param SCRIPT_FILENAME /opt/nginx/bugzilla/$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
    # attachments can be huge
    client_max_body_size 0;
    client_body_in_file_only clean;
    # this is where requests body are saved
    client_body_temp_path /opt/nginx/bugzilla/data/request_body 1 2;
}

and the client was doing a request with a URL that was about 6000 characters (a bugzilla request).

debugging...

location ~ ^.*\.cgi$ {
    error_log /var/log/nginx/bugzilla.log debug;
    # ...
}

This is what I got in the logs:

2015/03/18 10:24:40 [debug] 4625#0: *2 upstream split a header line in FastCGI records
2015/03/18 10:24:40 [error] 4625#0: *2 upstream sent too big header while reading response header from upstream, client: 10....

can I have "414 request-uri too large" instead of "502 bad gateway"?

Yes you can! I was reading How to set the allowed url length for a nginx request (error code: 414, uri too large) before because I thought "hey the URL's too long" but I was getting 502's rather than 414's.

large_client_header_buffers

Try #1:

# this goes in http or server block... so outside the location block
large_client_header_buffers 4 8k;

This fails, my URL is 6000 characters < 8k. Try #2:

large_client_header_buffers 4 4k;

Now I don't see a 502 Bad Gateway anymore and instead I see a 414 Request-URI Too Large

"upstream split a header line in FastCGI records"

Did some research and found somewhere on the internet:

  • http://forum.nginx.org/read.php?2,4704,4704
  • https://www.ruby-forum.com/topic/4422529
  • http://mailman.nginx.org/pipermail/nginx/2009-August/014709.html
  • http://mailman.nginx.org/pipermail/nginx/2009-August/014716.html

This was sufficient for me:

location ~ ^.*\.cgi$ {
    # holds request bigger than 4k but < 8k
    fastcgi_buffer_size 8k;
    # getconf PAGESIZE is 4k for me...
    fastcgi_buffers 16 4k;
    # ...
}