Before using Nginx did the Web reverse proxy, did not do load balancing, today there is a classmate need to do Tomcat load balancing, I also studied.
There are altogether 2 machines, one physical machine (Win7) that deploys 2 tomcat, using a different port to boot.
Virtual machine in VM (CentOS) nginx, load balance for tomcat.
- Inux ip:192.168.37.129
- Win ip:192.168.37.1
First, ensure that two hosts are able to ping each other, responding to the port open.
- nginx using the
- TOMCAT1 using 8081 tomcat2 using 8080
- nginx,tomcat installation and startup is not said, especially under Windows very easy. In the face of difficulties Baidu will be able to.
- windows installation start tomcat and a system to start multiple tomcat in order to differentiate each tomcat from the other. Add some logos to the HTML on the homepage.
- nginx version number 1.4 Tomcat version number 6.0
- 2 Tomcat instances can start normally, Nginx instances can also be used normally, win on the browser can normally visit 3 pages
- http ://192.168.37.1:8081/
- http://192.168.37.1:8080/
- http:// 192.168.37.129/
Then start configuring Nginx:
[Email protected] conf]# cat/etc/nginx/nginx.conf
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
upstream localhost {
server 192.168 37.1 : 8080 weight = 2
server 192.168 37.1 : 8081 weight = 1
#ip_hash;
}
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
proxy_connect_timeout 3;
#proxy_redirect off;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhost;
}
Error_page - 502 503 504 /50x.HTML;
location = / 50x html {
root html;
}
}
}
This How to restart Nginx did not take effect, the last discovery is due to the boot configuration file is incorrect. The ability to specify the path to accompany the configuration file via Nginx-c/etc/nginx/nginx.conf.
Of course, here is the simplest polling, no other strategy, the experiment is basically successful.
This article is from the "Orangleliu Notebook" blog, reproduced please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/41251397
Orangleliu
[Linux]nginx Tomcat doing load balancing