Error 400

  • Posted June 3, 2014

I just finished going through the following tutorial, but keep getting an error when trying to access my rails app:

When I access my droplet’s URL I get the following error: 400 Bad Request: Request Header Or Cookie Too Large

The nginx error log shows the following: client sent too long header line: "X-Forwarded-For: [my computer’s ip], [my droplet’s ip multiple times]

It looks like something is causing an infinite loop with the droplet IP, but I can’t find anywhere in the configuration that would cause that.

commenting the ‘X-Forwarded-For’ line in default.conf gets rid of the 400 error, but leads to a 502 Bad Gateway error.

Here is what I have in my default.conf (website info redacted):

upstream app { # Path to Unicorn SOCK file, as defined previously server unix:/tmp/unicorn.<redacted>.sock fail_timeout=0; }

server {

listen 80;
server_name localhost;

# Application root, as defined previously
root /usr/share/nginx/html/<redacted>;

try_files $uri/index.html $uri @<redacted>;

location @<redacted> {
   # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass <redacted>;

large_client_header_buffers 4 32k;
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;


I am unfortunately out of ideas so any help would be appreciated!

Thanks in advance!


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

No problem! Glad you got it working. <br> <br>It says “app” since that’s what the upstream is called: <br> <br><pre> <br>upstream app { <br># Path to Unicorn SOCK file, as defined previously <br>server unix:/tmp/unicorn…sock fail_timeout=0; <br>} <br></pre> <br> <br>but it could be anything. Those two values just need to match.

Awesome! Thanks! I didn’t realize that it was actually supposed to say ‘app’. That fixed everything up!

Hi Edward! <br> <br>The first thing that I notice is that your proxy pass setting isn’t going to work. You need to forward it to the upstream server, in your case “app.” <br> <br>So that line should look like: <br> <br><pre> <br>proxy_pass http://app; <br></pre> <br> <br>As for the “Request Header Or Cookie Too Large” error, you can try setting: <br> <br><pre> <br> large_client_header_buffers 4 32k; <br></pre> <br> <br>Check out the Nginx docs for more info on that: <br> <br>