By edwardtirado
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.<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!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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>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. <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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.