1, environment
Two (centos) machines, each machine running two web application
ip | web |
192.168.0.109 | http://192.168.0.109:8081 |
192.168.0.109 | http://192.168.0.109:8082 |
192.168.0.111 | http://192.168.0.111:8083 |
192.168.0.111 | http://192.168.0.111:8084 |
Note: Because this machine is my ubuntu system, I was on top of ubuntu system installed virtual machine, ran two centos7, if you find screenshots how so much like ubuntu colors, do not be surprised, the following screenshots are centos7, specific models as centos7-1810, web application preparation tool for the idea
2, web applications ready
In order to facilitate verification, a clean configuration application springboot
Please refer spring's official website: https: //spring.io/guides/gs/rest-service/
Based on the modifications performed, only the modified contents of return, the return port of the current application (application ports 4 respectively 8081,8082,8083,8084)
3, two machines were installed nginx Service
You can view the installation steps in the official website, for example, I was two centos machine
http://nginx.org/en/linux_packages.html#RHEL-CentOS
Reference mounting step mounting the official website
4, configure nginx
After installation, the profile location: / etc / nginx
Modify nginx.conf
vim nginx.conf
Add the http {}, click Contents:
server{ #nginx端口 listen 8080; #服务名称 server_name 192.168.0.109; location / { #proxy_pass 后边的地址需要与下方的upstream后边的名称一样 #此处为tomcats proxy_pass http://tomcats; root html; index index.html index.htm; } } #app的配置 upstream tomcats{ #weight为权重,值越大,分配的就越多 server 192.168.0.109:8081 weight=10; server 192.168.0.109:8082 weight=10; server 192.168.0.111:8083 weight=10; server 192.168.0.111:8084 weight=10; }
两台机器均要配置
5、启动nginx
我是在centos中根据官方文档在线安装,所以,命令可以直接调用
nginx
#停止命令 nginx -s stop
如下图:
证明nginx已经启动起来了,访问nginx,不断的刷新页面,会发现四个web应用均会被分配到: