Error 400

June 3, 2014 2.9k views
I just finished going through the following tutorial, but keep getting an error when trying to access my rails app: https://www.digitalocean.com/community/articles/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5 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..sock fail_timeout=0; } server { listen 80; server_name localhost; # Application root, as defined previously root /usr/share/nginx/html/; try_files $uri/index.html $uri @; location @ { # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass ; } 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!
3 Answers
Hi Edward!

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."

So that line should look like:


proxy_pass http://app;


As for the "Request Header Or Cookie Too Large" error, you can try setting:


large_client_header_buffers 4 32k;


Check out the Nginx docs for more info on that:

http://wiki.nginx.org/HttpCoreModule#large_client_header_buffers
Awesome! Thanks! I didn't realize that it was actually supposed to say 'app'. That fixed everything up!
No problem! Glad you got it working.

It says "app" since that's what the upstream is called:


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


but it could be anything. Those two values just need to match.
Have another answer? Share your knowledge.