Last active
December 24, 2016 02:52
-
-
Save zhouqiang-cl/49e5fb03e24aad5d61a2faac35e725a7 to your computer and use it in GitHub Desktop.
nginx 的 if-none-match 的错误
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
最近发现有人打不开我们主页,只在uc浏览器中复现. | |
nginx日志中是400,开启debug 发现有如下日志 | |
2016/12/23 12:14:11 [info] 40166#0: *2614733 client sent duplicate header line: "If-None-Match: "585b309f-1475"", | |
previous value: "If-None-Match: W/"585b309f-1475"" while reading client request headers, client: xx.xx.xx.xx, | |
server: www.xxx.com, request: "GET / HTTP/1.1" | |
猜测是uc浏览器某个版本之后不会对 if-none-match 去重, 而在nginx中 if-none-match 这个header 不可重复,不可忽略也无法去掉. | |
代码 | |
http://lxr.nginx.org/source/src/http/ngx_http_request.c#0099 | |
http://lxr.nginx.org/source/src/http/ngx_http_request.c#1586 | |
配置文件上是 fix 不了的, 只能依靠一些 trick 的方式. 我是这么改的 | |
error_page 400 = @workaround; | |
location @workaround { | |
rewrite ^(.*)$ $1 break; | |
} | |
这有几个缺点 | |
1. 只会将第一次的if-none-match 的header带过去 | |
2. if-none-match 后面的header忽略了, 所以依赖header决定转跳的配置代码可能不能正确work | |
所以这是一次有损的fix, 尽量不要使用这种, 而是在请求发起方处理 | |
另外所有的if 头和一些特定信息, 比如content-length都是一样的效果, 写client的时候别sb了, nginx这么处理是比较符合规范的 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment