2014-12-06 98 views
0

我有3臺服務器。第一臺服務器有nginx作爲負載平衡。第二和第三臺服務器有apache。在我的nginx的conf我有以下幾點:nginx負載平衡重定向404

upstream backend { 
    server ec2-54-148-248-231.us-west-2.compute.amazonaws.com; 
    server ec2-54-148-34-166.us-west-2.compute.amazonaws.com; 
} 

server { 
     listen 80 default_server; 
     listen [::]:80 default_server ipv6only=on; 

     root /usr/share/nginx/html; 
     index index.html index.htm; 

     # Make site accessible from http://localhost/ 
     server_name localhost; 

     location/{ 
       proxy_pass http://backend; 
       # First attempt to serve request as file, then 
       # as directory, then fall back to displaying a 404. 
       try_files $uri $uri/ =404; 
       # Uncomment to enable naxsi on this location 
       # include /etc/nginx/naxsi.rules 
     } 
} 

的問題是:當我打開第一個服務器重定向我的第二個或第三個,但我不能加載任何相對URL(例如:CSS或JS文件)在我的網站和所有鏈接返回一個404錯誤。

可以嘗試我的負荷balaning服務器上線URL =>http://ec2-54-148-96-241.us-west-2.compute.amazonaws.com/

+0

爲什麼你會把nginx放在Apache的頂端? – 2014-12-06 15:44:24

+0

然後重新思考你的建築。 – 2014-12-06 15:51:51

回答

0

我發現用循環或至少連接的負載均衡nginx的問題,每個後續客戶端的請求可以潛在地分配到不同的服務器。所以在我的網站做第一個請求除權後=>http://ec2-54-148-96-241.us-west-2.compute.amazonaws.com/site/index 然後作出要求http://ec2-54-148-96-241.us-west-2.compute.amazonaws.com/assets/f352c4d6/css/bootstrap.css它去到另一個服務器,但資產f352c4d6不是另一臺服務器上發現這樣返回404

解決方案: 必須使用ip_hash;與nginx負載平衡,以保持同一服務器爲一個IP 也可以使用leas_connect分配用戶到最少的服務器流量。