nginx反向代理caching重新调整错误

我们有一个embedded式http服务器的C / C ++应用程序。 我们的http服务器非常原生,不支持ssl或保持连接。 它侦听端口5555和服务器静态页面。 在服务页面之前,它会回应一下。 它还支持使用Etags进行cachingvalidation。 根据If-None-Match值,它发送304 Not Modifed 。 如果我们将浏览器redirect到some-ip:5555它工作的很好。 示例请求和响应标题如下

 Response Headers Cache-Control max-age=3600, must-revalidate Content-Encoding gzip Expires Wed, 15 May 2013 07:18:08 GMT Request Headers Accept */* Accept-Encoding gzip, deflate Accept-Language en-us,en;q=0.5 Cache-Control max-age=0 Connection keep-alive Host 127.0.0.1:5555 If-Modified-Since Tue, 08 May 2012 08:48:53 GMT If-None-Match "1336466933_85925" Referer http://127.0.0.1:5555/mlogin.html User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120425 Firefox/10.0.4 Response Headers From Cache Cache-Control max-age=3600, must-revalidate Content-Encoding gzip Content-Length 29832 Content-Type application/x-javascript Etag "1336466933_85925" Expires Wed, 15 May 2013 07:18:08 GMT Last-Modified Tue, 08 May 2012 08:48:53 GMT 

现在,当使用nginx反向代理尝试相同的设置时,它会502 Bad Gateway尝试重新validationcaching的所有页面提供502 Bad Gateway 。 它适用于Cache-Control no-cache所有页面。 我们的nginxconfiguration如下

 user nginx; worker_processes 1; error_log /var/log/nginx/error.log debug; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_requests 0; keepalive_timeout 0; server { server_name _; listen 80; location / { proxy_pass http://127.0.0.1:5555; 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; proxy_max_temp_file_size 0; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } } 

然后是响应和请求头

 Response Headers Connection close Content-Length 172 Content-Type text/html Date Tue, 15 May 2012 08:46:31 GMT Server nginx/1.2.0 Request Headers Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language en-us,en;q=0.5 Cache-Control max-age=0 Connection keep-alive Host 127.0.0.1 If-Modified-Since Tue, 08 May 2012 08:48:53 GMT If-None-Match "1336466933_85925" User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120425 Firefox/10.0.4 

在nginx错误日志中,我们得到这个错误

 2012/05/15 14:16:31 [error] 18832#0: *177 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET /lib/jquery-1.5.2.min.js?v=1330852144 HTTP/1.1", upstream: "http://127.0.0.1:5555/lib/jquery-1.5.2.min.js?v=1330852144", host: "127.0.0.1" 

任何人都可以提出什么问题? 提前致谢。

也许,你的HTTP服务器以某种方式破坏了HTTP协议,例如在最后一个头之后不发送额外的CRLF。