Home > Backend Development > PHP Tutorial > Nginx load balancing and dynamic and static separation

Nginx load balancing and dynamic and static separation

WBOY
Release: 2016-08-08 09:24:01
Original
1092 people have browsed it

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;
}
Copy after login
rr on server{} under reee
server的ip地址根据你的ip地址定义,可添加多个
Copy after login

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保持一致
}
Copy after login
The effect is as follows:


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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template