欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nginx報錯host not found in upstream的解決辦法

 更新時間:2023年08月17日 10:42:22   作者:風(fēng)神幻龍  
本文主要介紹了Nginx報錯host not found in upstream的解決辦法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

項目說明

前后臺分離項目,后臺所屬空間沒有存儲圖片,放置前臺空間存儲,后臺需要查看圖片,借助proxy_pass。對應(yīng)配置如下

test.conf

server {
    listen        80;
    server_name  admin.test.com;
    root  /www/test/admin
}
server {
    listen        80;
    server_name  www.test.com;
    root  /www/test/web
}

test.htaccess

try_files $uri $uri/ /index.html;
 location /uploads {    
    proxy_pass http://www.test.com/uploads;
 }

當(dāng)初配置完成的時候,啟動nginx并沒有問題,但是重啟系統(tǒng)之后,nginx卻是啟動不起來,報錯為

host not found in upstream "www.test.com" in test.htaccess

如果依照報錯去找答案,肯定會是找www.test.com是否真的能ping通,但是這個場景肯定無效,等服務(wù)器起來的時候,你ping www.test.com一定能ping通,因為這個解析就在你自己的服務(wù)器上,這也是為什么服務(wù)器啟動起來之后,操作nginx不會再報錯。但是在服務(wù)器啟動起來之前,ping www.test.com,因為服務(wù)器還未啟動起來(未驗證nginx的啟動順序是否比網(wǎng)絡(luò)更早)。
這樣的話,不使用www.test.com做proxy_pass不就行了,其實(shí)內(nèi)容既然在本機(jī)上放著,使用localhost其實(shí)就行。

server {
    listen        80;
    server_name  admin.test.com;
    root  /www/test/admin
}
server {
    listen        80;
    server_name  www.test.com;
    root  /www/test/web
}
server{
    listen 9001;
    server_name localhost;
    root  /www/test/web
}
try_files $uri $uri/ /index.html;
 location /uploads {    
    proxy_pass http://localhost:9001/uploads;
 }

這樣,重啟系統(tǒng)nginx也不會報錯了。

注意事項

自定義端口的時候,一定不要填寫一些特殊的端口,例如3306,6379等。

到此這篇關(guān)于Nginx報錯host not found in upstream的解決辦法的文章就介紹到這了,更多相關(guān)Nginx報錯host not found內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論