It is mainly the configuration jump of the if judgment in the location parameter. Diversion can reduce the load and pressure of the server. This is a very common server deployment architecture. #Domain name, IP, port and other information please modify it yourself upstream huaji-01.com { server 192.168.1.100:8080; } upstream huaji-02.com { server 192.168.1.200:8080; } server { listen 80; server_name www.huaji.com; location / { if ( $remote_addr ~* ^(.*)\.(.*)\.(.*)\.[1,125]$) { proxy_pass http://huaji-01.com; break; } proxy_pass http://huaji-02.com; } } The above example forwards requests with IP addresses ending in 1-125 to huaji-01.com, and others to huaji-02.com. You can also modify the regular expression, for example Rule: $remote_addr ~* ^(.*)\.(.*)\.(.*)\.*[0268]$ Even-numbered IPs ending with 0268 will jump to huaji-01.com, and others will jump to the second domain name; Rule: $remote_addr ~* ^(112)\.(.*)\.(.*)\.(.*)$ IPs starting with 112 will be redirected to the specified domain name; Rule: $http_x_forwarded_for ~* ^(112)\.(.*)\.(.*)\.(.*)$ Divert traffic based on the forward address segment, and redirect traffic starting with 112 to the specified domain name The meaning of if instruction conditional judgment: Regular expression matching where: ~ for case-sensitive matching ~* is case-insensitive matching !~ and !~* are case-sensitive and case-insensitive matches respectively. File and directory matching, where: -f and !-f are used to determine whether a file exists -d and !-d are used to determine whether a directory exists -e and !-e are used to determine whether a file or directory exists -x and !-x are used to determine whether the file is executable The last parameter of the rewrite directive is the flag tag, which includes: last is equivalent to the [L] flag in Apache, which means rewrite. break After this rule is matched, the matching is terminated and the following rules will no longer be matched. redirect returns a 302 temporary redirect, and the browser address will display the URL address after the jump. permanent returns 301 permanent redirection, and the browser address will display the URL address after the jump. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Vue improves page response speed through lazy loading
>>: MySQL Packet for query is too large problem and solution
Table of contents 1. What is multi-instance 2. Pr...
Table of contents What is FormData? A practical e...
Table of contents 1. What is a design pattern? 2....
1. Download the MySQL jdbc driver (mysql-connecto...
Table of contents 1. Environmental Preparation 2....
Table of contents Identifier length limit Length ...
Similar to the code hosting service provided by G...
Windows Server 2019 is the latest server operatin...
A master once said that you should know the datab...
This tutorial shares the installation and configu...
1 Introduction Redis is a high-performance NoSQL ...
Problems that may arise from optimization Optimiz...
Table of contents 1. Problem Description 2. Probl...
1. Create a database authorization statement >...
[LeetCode] 197.Rising Temperature Given a Weather...