我是nginx的新手(过去使用过Apache).
目前,我正在尝试设置一个将缓存在apache后端的缓存,最终,我认为(根据我到目前为止对nginx的良好经验),我们将切换为仅使用nginx.
当我打开http2时,Safari无法获得响应.在错误日志中,没有任何内容表明有问题,如果打开访问日志并检查那里,我可以看到Safari客户端进行了许多连接,这就像是不断刷新页面一样.
我已经尝试了许多nginx版本,因为我注意到最新的稳定版可能存在问题.因此,我尝试降级到1.9.14以及升级到1.11.1,但都没有运气.
Nginx的编译方式如下:
./configure –with-http_ssl_module –with-http_v2_module
Nginx -V输出:
nginx version: nginx/1.11.1
built by gcc 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2.1)
built with OpenSSL 1.0.2g-fips 1 Mar 2016
TLS SNI support enabled
configure arguments: --with-http_ssl_module --with-http_v2_module
我的配置如下所示(我的网站可用的conf):
upstream backend {
server 127.0.0.1:8088 weight=100;
}
server {
listen 443 ssl http2 deferred;
server_name www.server.name;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK";
ssl_prefer_server_ciphers on;
ssl_certificate /path/to/cert.crt
ssl_certificate_key /path/to/cert_key.key
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
location / {
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_pass https://backend;
}
}
如果我从listen参数中删除http2并重新启动,则可以正常工作…
我一直在搜索以确定配置中是否做错了什么,但找不到任何东西…但是,如果我的配置有一些改进,请告诉我.然而,主要的问题是,每当我使用Safari命中一个URL(是否缓存)时,它都会不断加载.
这是请求后我的访问日志的样子:
123.123.123.123 - - [11/Jun/2016:08:37:28 +0200] "GET /example/url HTTP/2.0" 200 15032 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17"
123.123.123.123 - - [11/Jun/2016:08:37:28 +0200] "GET /example/url HTTP/2.0" 200 15032 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17"
123.123.123.123 - - [11/Jun/2016:08:37:28 +0200] "GET /example/url HTTP/2.0" 200 15032 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17"
123.123.123.123 - - [11/Jun/2016:08:37:28 +0200] "GET /example/url HTTP/2.0" 200 15032 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17"
123.123.123.123 - - [11/Jun/2016:08:37:28 +0200] "GET /example/url HTTP/2.0" 200 15032 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17"
123.123.123.123 - - [11/Jun/2016:08:37:28 +0200] "GET /example/url HTTP/2.0" 200 15032 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17"
123.123.123.123 - - [11/Jun/2016:08:37:28 +0200] "GET /example/url HTTP/2.0" 200 15032 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17"
谢谢!
解决方法:
好!经过大量研究和测试,结果表明我需要在配置中隐藏Upgrade标头. proxy_hide_header升级;
在这里阅读更多:https://trac.nginx.org/nginx/ticket/915