For the installation of Nginx, please see the previous article
Load balancing + dynamic and static separationModify nginx/conf/nginx.conf
Open the original file, vim /usr/local/nginx/conf/nginx .conf
Load balancing:
Find server{}, add
upstream tomcat { server 192.168.142.131:8080 weight=1 max_fails=1 fail_timeout=30s; server 192.168.142.132:8080 weight=1 max_fails=2 fail_timeout=30s; server 192.168.142.133:8080 weight=1 max_fails=1 fail_timeout=30s; }
server的ip地址根据你的ip地址定义,可添加多个
server listen 80; You can modify the port number yourself
After the modification is completed, save and restart.
Visit localhost:8888 to display the tomcat homepage of the other three machines.
Separation of dynamic and static:
vim /usr/local/nginx/conf/nginx.conf
Add above location / {}
location / { root html; index index.html index.htm; } 替换为 location / { root html; index index.html index.htm; proxy_connect_timeout 3; proxy_send_timeout 30; proxy_read_timeout 30; proxy_pass http://tomcat; //tomcat和上边定义的upstream tomcat保持一致 }
Save, restart Nginx, visit localhost: 8888,
Files such as images and css displayed on the Tomcat homepage will not be displayed. Copy the files to the staticDate file under Nginx, then will be displayed.
The above introduces Nginx's load balancing and dynamic and static separation, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.