解決nginx配置負載均衡時invalid host in upstream報錯


當前平台: windows

nginx版本: 1.11.5

前言: 在配置負載均衡時,同時也需要設置反向代理,當修改了nginx.conf時,發現nginx服務無法開啟。

1. 打開"nginx/logs/error.log",查看最新的錯誤日志, invalid host in upstream

紅色: 后端服務器的主機無效,藍色: 主機地址: http://192.168.29.128  綠色: 錯誤行數在nginx.conf的55行。   大概的也就出來了,就是設定負載均衡服務器的128主機無法訪問,或者拒絕訪問等等。

2. 查看設定負載均衡服務器列表的地方

upstream webservers { server http://127.0.0.1 weight=10; server htpp://192.168.29.130 weight=10; }

3. 查看虛擬服務器vhosts.conf的配置

server { listen 80; server_name www.bjy.com www.bjy.com; root "D:\set-soft\phpstudy2018\PHPTutorial\WWW\baijunyao-bjyadmin"; location / { proxy_pass http://webservers; proxy_set_header X-Real-IP $remote_addr; #后端的Web服務器可以通過X-Forwarded-For獲取用戶真實IP proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }

4. 發現反向代理的proxy_pass里和負載均衡服務器列表都帶了http://,而webservers就已經代表了服務器列表中的一個,所以只需在列表中的地址去除http://就可以。

 

有什么問題可以在下面公眾號下留言


免責聲明!

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



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