nginx负载均衡
准备条件:
三台CentOS6虚拟机分别部署nginx、tomcat、tomcat服务器各一台
设置在同一网段
CentOS-nginx:
IP 10.1.1.1/24
安装Nginx:
CentOS-tomcat:
IP:10.1.1.10/24
上传nginx.tar.gz 包后;
tar -zxf nginx.tar.gz
生成makefile
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module
编译安装
make && make install
cd /usr/local/nginx/conf
vim nginx.conf
http{}中添加:
upstream tomcatserver{ server 10.1.1.10:8080 weight=1; server 10.1.1.20:8080 weight=1; }
location{}中添加:
proxy_pass http://tomcatserver;
进入到sbin 下;
useradd -s /sbin/nologin -M nginx //指定nginx用户 ./nginx //开启nginx
其他
对于另外两台虚拟机:
分别安装tomcat,
修改webapps/ROOT/index.jsp 页面
开启;
验证
nignx机器访问ip:10.1.1.1 (127.0.0.1)
会加载出
tomcat10 或者tomcat20的页面