nginx : server_name localhost 和 chrome : Provisional headers are shown
问题相关
nginx : server_name localhost
chrome : Provisional headers are shown
问题现象:
使用nginx做代理,代理图片请求。
#nginx.conf
server {
listen 80;
server_name localhost;
location ^~ /img/ {
proxy_pass http://localhost:8000/;
}
server {
listen 8000;
server_name localhost;
location /{
root D:\\img;
}
}
用户chrome浏览器打开 localhost
第一次打开页面加载图片正常,
F5刷新后,
图片就加载不出来了,
再F5刷新,图片又可以加载出来,
再F5刷新,图片又加载不出来了。
总结,奇数次可以加载出来,偶数次加载不出来。
解决思路
F12 查看请求信息
查看nginx的错误日志
#error.log
upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /img/1.jpg HTTP/1.1", upstream: "http://[::1]:8000/1.jpg", host: "localhost", referrer: "http://localhost/"
然后一点点思路也没有。
多次操作后,意识到可能是server_name localhost用的不对。改为用127.0.0.1
然后就可以了,解决了!!:joy::joy::joy:
解决方案
nginx.conf 文件里的localhost全改为用127.0.0.1.
(本地IP:192.168.1.x 也可以)
#nginx.conf
server {
listen 80;
server_name 127.0.0.1;
location ^~ /img/ {
proxy_pass http://127.0.0.1:8000/;
}
server {
listen 8000;
server_name 127.0.0.1;
location /{
root D:\\img;
}
}
总结
现在也没想明白是怎么回事,请大大们指教。