1. 程式人生 > >nginx叢集報錯“upstream”directive is not allow here 錯誤 [

nginx叢集報錯“upstream”directive is not allow here 錯誤 [

nginx叢集報錯“upstream”directive is not allow here 錯誤
搭建了一個伺服器, 採用的是nginx + apache(多個) + php + mysql(兩個) 多個apache負載均衡及後端mysql讀寫分離的伺服器.

當然如果網站流量小的話 就完全沒有必要了! 一是搭建起來麻煩,二也增加了維護成本! 當你網站流量達到一定級別不考慮也得考慮了.

當設定好 upstream 如下:

upstream backend { server backend1.example.com weight=5; server backend2.example.com:8080; server unix:/tmp/backend3;}
執行命令:/usr/local/nginx/sbin/nginx -s reload 時 報錯如下:

[emerg]: “upstream” directive is not allowed here in /usr/local/nginx/conf/nginx.conf:52

後來檢查了一下原來是upstream backend 位置放錯了, upstream位置應該放在http模組裡面 但必須是在server模組的外面. 應該是下面這樣的結構:

http{upstream backend { server backend1.example.com weight=5; server backend2.example.com:8080; server unix:/tmp/backend3;} server { location / { proxy_pass

http://backend; }}}
如果你配置的伺服器也如類似的錯誤 不妨檢查你的upstream位置是否正確!

18