Adam

Nginx 502 Bad Gateway Error

by Adam on February 1, 2010

in Quick Tips

If you get the following error thrown from nginx:

“upstream sent too big header while reading response header from upstream”

you might well need to increase your proxy header sizes in the config to:

proxy_connect_timeout 90;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_buffer_size 16k;
proxy_buffers 8 16k;
proxy_busy_buffers_size 32k;
proxy_intercept_errors on;

We were stuffing quite a few cookies in the header for session related things and apparently it was too much for the default nginx config to handle.

Via: Adrian Nuta.

Related posts:

  1. Tweetfactor – An experiment using Ruby, Sinatra, Twitter and Redis

{ 3 comments… read them below or add one }

Jay March 5, 2010 at 5:22 am

Hi, maybe you could help me with this..
Im using ubuntu 9.10 nginx + php-fastcgi.
Everything was working fine until i did a apt-get upgrade.

i now get a Bad gateway 502

the error: [error] 1199#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.100, server: test.domain.com, request: “GET / HTTP/1.1″, upstream: “fastcgi://127.0.0.1:9000″

Reply

Adam March 10, 2010 at 5:04 pm

@Jay: Sounds like it’s failing to communicate with the fastcgi process / not proxying correctly.

Sorry I can’t be of more help. Try #nginx on irc.freenode.net

Reply

Cebu Tech Blogger August 30, 2010 at 7:35 pm

I’m encountering similar 502 Gateway Error (typing my site w/o ‘www’), but really had a doubt if it’s a server side or just a setting on my blogging platform. It appears I already set everything right, yet it still return the same error… grrr…

Reply

Leave a Comment