問題相關
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;
}
}
總結
現在也沒想明白是怎么回事,請大大們指教。
