2

我有一个通过 CherryPy 的 WSGI 服务器提供的 Python 应用程序,它接收来自 Nginx 的请求。它托管在 Windows Server 2003 机器上,只有少数用户访问它。

有时,对特定资源的请求几乎会立即失败,并在 Firefox 上出现502 Bad Gateway 。我试图在其他浏览器上重现该问题,但没有成功。

应用程序是这样启动的:

paths = { "/resource": resource_func }
dispatcher = wsgiserver.WSGIPathInfoDispatcher(paths)
server = wsgiserver.CherryPyWSGIServer(("127.0.0.1", 9191), dispatcher)
server.start()

nginx 服务器通过以下方式向 CherryPy 转发请求proxy_pass

location / {
    proxy_pass         http://127.0.0.1:9191/;
    proxy_redirect     off;

    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

请求通过 jQuery.ajax 方法发送:

$.ajax(requestURI).done(myRequestCallback);

如果我运行 Firebug,然后在出现 502 时打开 nginx 错误日志,我会看到以下错误:

(time): *92 WSASend() failed (10054: An existing connection was forcibly closed by the remote host) while sending request to upstream, client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /resource?params=VALUES&_=1371674388573 HTTP/1.1", upstream: "http://127.0.0.1:9191/resource?params=VALUES&_=1371674388573", host: "xxx.xxx.xxx.xxx:9080", referrer: "http://172.27.129.112:9080/myAppPage.html"

...xxx.xxx.xxx.xxx我正在测试应用程序的 IP 在哪里,而 nginx 正在侦听9080.

失败的请求不会显示在我们应用程序的日志文件中,并且相同的资源和参数是有效的(请求不会在每次尝试时都失败)。

我什至在我的 nginx.conf 文件中添加了以下几行(然后重新启动了两台服务器)以尝试解决问题,但似乎没有任何区别:

proxy_buffers 8 16k;
proxy_buffer_size 32k;

版本是:

  • 火狐 21
  • Python 2.7.5
  • nginx 1.2.0
  • 樱桃派 3.2.2

什么可能导致错误?

4

1 回答 1

0

当我看到这个(不是使用 CherryPy,而是使用 Gunicorn/others)时,这是因为服务器正在重新启动并且 Nginx 无法连接到它。服务器上是否发生了其他可能导致 CherryPy 重新启动的事情?

于 2013-06-19T23:19:19.227 回答