如何调试HTTP 502错误? [英] How do I debug a HTTP 502 error?

查看:1139
本文介绍了如何调试HTTP 502错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Nginx前端后面有一个Python Tornado服务器.有时但并非每次都出现502错误.我查看了nginx访问日志,然后看到了:

I have a Python Tornado server sitting behind a nginx frontend. Every now and then, but not every time, I get a 502 error. I look in the nginx access log and I see this:

127.0.0.1 - - [02/Jun/2010:18:04:02 -0400] "POST /a/question/updates HTTP/1.1" 502 173 "http://localhost/tagged/python" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"

,并在错误日志中:

2010/06/02 18:04:02 [error] 14033#0: *1700 connect() failed (111: Connection refused)
while connecting to upstream, client: 127.0.0.1, server: _,
request: "POST /a/question/updates HTTP/1.1",
upstream: "http://127.0.0.1:8888/a/question/updates", host: "localhost", referrer: "http://localhost/tagged/python"

我不认为任何错误会出现在龙卷风日志中.您将如何调试它?我可以在Tornado或nginx配置中添加一些内容来帮助调试吗?

I don't think any errors show up in the Tornado log. How would you go about debugging this? Is there something I can put in the Tornado or nginx configuration to help debug this?

推荐答案

在我看来,错误日志中的内容非常有用.它说上游拒绝了该连接,它包含客户端IP,Nginx服务器配置,请求行,主机名,上游URL和引荐来源网址.

The line from the error log is very informative in my opinion. It says the connection was refused by the upstream, it contains client IP, Nginx server config, request line, hostname, upstream URL and referrer.

很明显,您必须查看上游(或防火墙)以找出原因.

It is pretty clear you must look at the upstream (or firewall) to find out the reason.

如果您想了解Nginx如何处理请求,为什么要选择特定的服务器和位置部分-有一个漂亮的调试"模式. (请注意,您的Nginx二进制文件必须使用包含的调试符号来构建).然后:

In case you'd like to look at how Nginx processes the request, why it chooses specific server and location sections -- there is a beautiful "debug" mode. (Note, your Nginx binary must be built with debugging symbols included). Then:

error_log  /path/to/your/error.log debug;

将打开所有请求的调试.在错误日志中调试信息需要一些时间来习惯于对其进行解释,但这是值得的.

will turn on debugging for all the requests. Debugging information in the error log requires some time to get used to interpret it, but it's worth the efforts.

对于高流量的网站,请勿按原样"使用此!它会生成很多信息,并且您的错误日志将会非常快地增长.如果需要在生产环境中调试请求,请使用debug_connection指令:

Do not use this "as is" for high traffic sites! It generates a lot of information and your error log will grow very fast. If you need to debug requests in the production, use debug_connection directive:

events {
  debug_connection 1.2.3.4;
}

仅打开特定客户端IP地址的调试.

It turns debugging on for the specific client IP address only.

这篇关于如何调试HTTP 502错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆