Article Directory
1nginx.conf file
Mainly modify the server
2 reverse proxy
Reverse proxy, in fact, a client of the agency is not aware of, because the client does not need any configuration you can visit, we only
need to send a request to the reverse proxy server, the reverse proxy server to select the target server to get data, When it is returned
to the client, the reverse proxy server and the target server are external servers, and the
address of the proxy server is exposed , but the real server IP address is hidden.
Reverse proxy:
1. The reverse proxy server is configured on the server side.
2. The client does not know which server is being accessed.
3. Load balance is achieved and the real IP address of the server can be hidden.
3 About Nginx's location path mapping
Priority relationship:
(location =)> (location /xxx/yyy/zzz)> (location ^~)> (location
, *)> (location /starting path)> (location /)
![](https://img-blog.csdnimg.cn/20201027105131158.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0luc2lzdF9fXw==,size_16,color_FFFFFF,t_70#pic_center)
#Visit http://192.168.199.109/index to enter the tomcat homepage
#Visit http://192.168.199.109/ssm to enter the ssm project homepage
#Visit http://192.168.199.109/ to enter Hello Nginx!!
Port 80 is the default network port, no need to add 80 to access
4 load balancing
A single server can not be resolved, we increase the number of servers, then distribute requests to each server, and the original
request for the case to focus on a single server instead distribute requests across multiple servers, the load is distributed to different service
traffic control , Which is what we call load balancing
4.1 Polling
example:
upstream my_server{
server ncthz.top:8080;
server ncthz.top:8081;
}
server {
listen 80;
listen [::]:80;
server_name localhost;//即ncthz.top
location / {
proxy_pass http://my_server/; #tomcat首页
}
}
Refresh the ncthz.top page several times, according to the version number we can find that we have entered a different tomcat
4.2 Weight
![](https://img-blog.csdnimg.cn/20201027111929717.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0luc2lzdF9fXw==,size_16,color_FFFFFF,t_70#pic_center)
4.3 ip_hash
![](https://img-blog.csdnimg.cn/20201027112056248.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0luc2lzdF9fXw==,size_16,color_FFFFFF,t_70#pic_center)
5 Dynamic and static separation
Nginx's concurrency formula:
worker_processes * worker_connections / 4|2 = Nginx's final concurrency.
Dynamic resource requirement/4, static resource requirement/2
Nginx uses dynamic and static separation to improve Nginx's concurrency capacity and respond to users faster (no need Access server, increase speed)
6 clusters
单点故障,避免nginx的宕机,导致整个程序的崩溃
准备多台Nginx
准备keepalived,监听nginx的健康情况
准备haproxy,提供一个虚拟的路径,统一的去接收用户的请求
reference
1
https://blog.csdn.net/m0_49558851/article/details/107786372
2
https://nishigouzi.github.io/2020/06/07/Nginx%E7%AC%94%E8%AE%B0/#more
corresponds to the brain map
https://besterwin.gitee.io/blogs/knowledge/middle /Nginx.html
3
https://www.bookstack.cn/read/dunwu-nginx-tutorial/spilt.6.docs-nginx-configuration.md