Nginx 502 Bad Gateway 错误仅在 Firefox 中

发布于 2024-09-19 06:33:26 字数 1487 浏览 11 评论 0原文

我在本地运行一个网站,所有流量都通过 NGinx 路由,然后将 PHP 页面的请求分派给 Apache 并提供静态文件。在 Chrome、Safari、IE 等中完美运行。

但是,每当我在 Firefox 中打开网站时,我都会收到以下错误:

502 Bad Gateway
nginx/0.7.65

如果我清除缓存和 cookie,然后重新启动 FireFox,我可以在之前加载该网站一两次错误返回。我尝试过 Firefox 3.6 和 3.5,都有同样的问题。

这是我的 Nginx 配置的样子:

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; 
 }
}

这是 Firefox 在我的 error.log 文件中生成的错误:

[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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

聆听风音 2024-09-26 06:33:26

我似乎找到了解决我的问题的方法。经过一些额外的 Google 研究后,我将以下几行添加到我的 Nginx 配置中:

proxy_buffers 8 16k;
proxy_buffer_size 32k;

但是,我仍然不知道为什么这有效以及为什么只有 Firefox 似乎有问题。如果有人能阐明这一点,或者提供更好的解决方案,将不胜感激!

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!

萌面超妹 2024-09-26 06:33:26

如果你有 firePHP 禁用它。大标头会导致 nginx 与 php 通信时出现问题。

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

小红帽 2024-09-26 06:33:26

增加代理缓冲区的大小可以解决此问题。 Firefox 允许将大型 cookie(每个最多 4k)附加到每个请求。 Nginx 默认配置的缓冲区很小(只有 4k)。如果您的流量使用大cookie,您将在 nginx 错误日志中看到错误“upstream sent Too big header while Reading response header”,并且 Nginx 将向客户端返回 http 502 错误。发生的情况是 Nginx 在解析和处理请求时耗尽了缓冲区空间。

要解决此问题,请更改 nginx.conf 文件

proxy_buffers 8 16k;
proxy_buffer_size 32k;

- 或 -

fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

Increasing the size of your proxy buffers solves this issue. Firefox allows large cookies (up to 4k each) that are attached to every request. The Nginx default config has small buffers (only 4k). If your traffic uses big cookies, you will see the error "upstream sent too big header while reading response header" in your nginx error log, and Nginx will return a http 502 error to the client. What happened is Nginx ran out of buffer space while parsing and processing the request.

To solve this, change your nginx.conf file

proxy_buffers 8 16k;
proxy_buffer_size 32k;

-or-

fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

ㄖ落Θ余辉 2024-09-26 06:33:26

打开 /etc/nginx/nginx.conf 并
将以下行添加到 http 部分:

fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

此修复在 CI Web 应用程序中对我有用。阅读更多信息 http://www.adminsehow.com /2012/01/fix-nginx-502-bad-gateway-error/

open /etc/nginx/nginx.conf and
add the following lines into http section :

fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

This fix worked for me in a CI web application. read more at http://www.adminsehow.com/2012/01/fix-nginx-502-bad-gateway-error/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文