nginx : server_name localhost 和 chrome : Provisional headers are shown


問題相關

nginx : server_name localhost
chrome : Provisional headers are shown

問題現象:

使用nginx做代理,代理圖片請求。

 
 
 
         
  1. #nginx.conf
  2. server {
  3. listen 80;
  4. server_name localhost;
  5. location ^~ /img/ {
  6. proxy_pass http://localhost:8000/;
  7. }
  8. server {
  9. listen 8000;
  10. server_name localhost;
  11. location /{
  12. root D:\\img;
  13. }
  14. }

用戶chrome瀏覽器打開 localhost
第一次打開頁面加載圖片正常,
F5刷新后,
圖片就加載不出來了,
再F5刷新,圖片又可以加載出來,
再F5刷新,圖片又加載不出來了。
總結,奇數次可以加載出來,偶數次加載不出來。

解決思路

F12 查看請求信息

查看nginx的錯誤日志

 
 
 
         
  1. #error.log
  2. 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 也可以)

 
 
 
         
  1. #nginx.conf
  2. server {
  3. listen 80;
  4. server_name 127.0.0.1;
  5. location ^~ /img/ {
  6. proxy_pass http://127.0.0.1:8000/;
  7. }
  8. server {
  9. listen 8000;
  10. server_name 127.0.0.1;
  11. location /{
  12. root D:\\img;
  13. }
  14. }

總結

現在也沒想明白是怎么回事,請大大們指教。






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM