Welcome! Log In Create A New Profile

Advanced

nginx load balance

Posted by sam.gu 
nginx load balance
October 09, 2013 10:24PM
Now, my envir is Ngnix 1.4.2+Jboss as 7.i met some questions about load balance. It's not any question when i using ip_hash.But,if i using weight ,i can't login my app, will be logout my app when i enter user and pass.
The below is the content of access.log. it's be logout myapp after login. it's no problem if using ip hash.:
192.168.6.143 - - [10/Oct/2013:10:15:19 +0800] "GET /myapp/ HTTP/1.1" 302 0 "-" "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
192.168.6.143 - - [10/Oct/2013:10:15:19 +0800] "GET /myapp/index.action HTTP/1.1" 302 0 "-" "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
192.168.6.143 - - [10/Oct/2013:10:15:19 +0800] "GET /myapp/logout.jsp HTTP/1.1" 200 876 "-" "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
192.168.6.143 - - [10/Oct/2013:10:15:19 +0800] "GET /myapp/login.action HTTP/1.1" 200 10295 "http://192.168.6.143/myapp/logout.jsp" "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
192.168.6.143 - - [10/Oct/2013:10:15:24 +0800] "POST /myapp/j_spring_security_check HTTP/1.1" 302 0 "http://192.168.6.143/myapp/login.action" "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
192.168.6.143 - - [10/Oct/2013:10:15:24 +0800] "GET /myapp/ HTTP/1.1" 302 0 "http://192.168.6.143/mypp/login.action" "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
192.168.6.143 - - [10/Oct/2013:10:15:24 +0800] "GET /uma-unimax-web/logout.jsp HTTP/1.1" 200 876 "http://192.168.6.143/uma-unimax-web/login.action" "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
192.168.6.143 - - [10/Oct/2013:10:15:24 +0800] "GET /uma-unimax-web/login.action HTTP/1.1" 200 10295 "http://192.168.6.143/uma-unimax-web/logout.jsp" "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
The below is my nginx conf:
upstream myapp {
#ip_hash;
server 10.1.1.199:8331 weight=5 max_fails=3 fail_timeout=30s;
server 10.1.1.199:8330 weight=5 max_fails=3 fail_timeout=30s;
}

server {
listen 80;
server_name 192.168.6.143;
large_client_header_buffers 4 16k;
client_max_body_size 300m;
client_body_buffer_size 128k;
proxy_connect_timeout 3;
proxy_read_timeout 3;
proxy_send_timeout 5;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

include block_session.conf;

#charset koi8-r;


location ~ ^/status {
stub_status on; #Nginx monitor
access_log off;
}
location ~ ^/(WEB-INF)/ {
deny all;
}

location / {
#root html;
#index index.html index.htm;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header Host $http_host;
#proxy_set_header X-NginX-Proxy true;
proxy_pass http://myapp;
#proxy_redirect off;
#proxy_pass_header Set-Cookie;

}
Re: nginx load balance
January 30, 2014 01:35PM
The iphash method is doing bascily acting as a sticky bit. All your requests come from the same IP it is makes sence that it would always go to that server.

Using the weighed method, in this case is equal weight so its going to round robin the connections iirc.

The failing isn't nginx LB, its that your app requires session presistance to one server.

nginx is a OK LB, I would suggest looking else where if you cant change your app to not require session presistance to one server.

Maybe store the session ID in redis/memcache so both yor servers dont create a new id each time.

-Erik-
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 80
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready