Nginx Nginx 反向代理回来会将 etag、last_modified header 删除

winterwhisper · November 20, 2015 · Last by winterwhisper replied at November 20, 2015 · 9294 hits

已知 nginx 1.7.3 以下的版本会在 gzip 的过程中 remove 掉 etag,已经将 nginx 升级到 1.8.0,rails 后端返回的也是 weak etag。

用浏览器访问(get 请求)观察 nginx debug 日志发现如下

2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy status 200 "200 OK "
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "Etag: W/"89a9be4e07c81409d305591384a34d8f""
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "Last-Modified: Thu, 19 Nov 2015 02:37:54 GMT"
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "Content-Type: text/html; charset=utf-8"
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "Cache-Control: max-age=0, private, must-revalidate"
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "X-Ua-Compatible: IE=Edge"
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "X-Request-Id: b84d7a6314f2010e93e0d01684ec8bf5"
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "X-Runtime: 0.048106"
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-10-27)"
2015/11/20 11:54:43 [debug] 16796#0: *573 posix_memalign: 00007FC78105FE00:4096 @16
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "Date: Fri, 20 Nov 2015 03:54:43 GMT"
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "Content-Length: 9756"
2015/11/20 11:54:43 [debug] 16796#0: *573 http proxy header: "Connection: close"

上面是 webrick 返回给 nginx 的,然后 nginx 返回给 client 的就变成

Server: nginx/1.8.0^M
Date: Fri, 20 Nov 2015 03:54:43 GMT^M
Content-Type: text/html; charset=utf-8^M
Transfer-Encoding: chunked^M
Connection: keep-alive^M
Cache-Control: max-age=0, private, must-revalidate^M
X-Ua-Compatible: IE=Edge^M
X-Request-Id: b84d7a6314f2010e93e0d01684ec8bf5^M
X-Runtime: 0.048106

但用 curl 发一个 head 请求发现没有问题,存在 etag 和 last_modified

感觉像是 nginx 在 webrick 返回过来的途中把 etag、Last-Modified 给 drop 掉了,求问各位有没有碰到过类似情况。

找到原因了,是因为 nginx 开启了 ssi。

You need to Sign in before reply, if you don't have an account, please Sign up first.