Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx 502 Bad Gateway error ONLY in Firefox

I am running a website locally, all the traffic is routed through NGinx which then dispatches requests to PHP pages to Apache and serves static files. Works perfectly in Chrome, Safari, IE, etc.

However, whenever I open the website in Firefox I get the following error:

502 Bad Gateway
nginx/0.7.65

If I clear out cache and cookies, and then restart FireFox, I am able to load the site once or twice before the error returns. I've tried both Firefox 3.6 and 3.5 and both have the same problem.

Here is what my Nginx config looks like:

worker_processes  2;

events {
    worker_connections  1024;
}


http {

 server {
     listen        80;
     server_name   local.mysite.amc;
     root          /Users/joshmaker/Sites/mysite;

  error_log  /var/log/nginx/error.log;
  access_log  /var/log/nginx/access.log;

     location / {
         proxy_set_header Host $host;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_pass http://local.mysite.amc:8080;
     }

  include /opt/local/etc/nginx/rewrite.txt;
 }
 server {  
  include /opt/local/etc/nginx/mime.types;

     listen        80;
     server_name   local.static.mysite.amc;
     root          /Users/joshmaker/Sites/mysite;

  error_log  /var/log/nginx/error.log;
  access_log  /var/log/nginx/access.log; 
 }
}

And here is the errors that Firefox generates in my error.log file:

[error] 11013#0: *26 kevent() reported that connect() failed (61: Connection refused) while connecting to upstream     
[error] 11013#0: *30 upstream sent too big header while reading response header from upstream
[error] 11013#0: *30 no live upstreams while connecting to upstream

I am completely at a loss why a browser would cause a server error. Can someone help?

like image 378
Joshmaker Avatar asked Sep 13 '10 21:09

Joshmaker


People also ask

Why is my 502 Bad gateway nginx?

A 502 Bad Gateway indicates that the edge server (server acting as a proxy) could not get a valid or any response from the origin server (also called the upstream server).

Does 502 Bad gateway get fixed?

Note: A Gateway might refer to different things in networking and a 502 error is usually not something you can fix, but requires a fix by the web server or the proxies you are trying to get access through.


2 Answers

I seem to have found a work around that fixed my problem. After some additional Google research, I added the following lines to my Nginx config:

proxy_buffers 8 16k;
proxy_buffer_size 32k;

However, I still don't know why this worked and why only Firefox seemed to have problems. If anyone can shed light on this, or offer a better solution, it would be much appreciated!

like image 160
Joshmaker Avatar answered Oct 08 '22 10:10

Joshmaker


If you have firePHP disable it. Big headers causes problems while nginx comunication with php.

like image 44
nerkn Avatar answered Oct 08 '22 09:10

nerkn