nginx做负载后为什么超级慢

csonezp 发布于 2014/12/31 14:22
阅读 7K+
收藏 0

server 2012服务器,刚学着搭建的nginx,就做了个均衡,把所有请求发到两个tomcat上,

upstream local {  
       server localhost:8080;  
       server localhost:8081;  
    }  

    server {
        listen       80;
        server_name  localhost;
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|html)$ {
        expires      30d; 
        }
    location ~ ^/(WEB-INF)/ { 
            deny all;  
    }  
    location / {
    
        proxy_pass http://local;
    }
}

然后打开localhost,间歇性的非常卡,10秒都加载不出来页面。

错误日志里有这些记录,请问这问题该怎么解决?

2014/12/31 06:10:45 [error] 3204#688: *4 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://[::1]:8081/", host: "localhost"


2014/12/31 06:10:45 [error] 3204#688: *4 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://[::1]:8081/", host: "localhost"

加载中
1
首席吊炸天
首席吊炸天
nginx默认负载均衡策略是轮询的,根据错误日志,你该检查localhost 8081端口情况
1
G
Georger

经过测试,upstream xxx 中加入ip_hash就不卡了,原因不知道,原谅我是菜鸟

upstream test {
      ip_hash;
      server localhost:8081;
      server localhost:8080;
     }

w
wuyichen
那是因为你的ip都是localhost,用iphash最终只会访问一个端口
返回顶部
顶部