2014-12-06 149 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分配用户到最少的服务器流量。