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 Summarize Sometimes we need to ...
Basic concepts of consul Server mode and client m...
Table of contents Overview 1. Compositon API 1. W...
This article uses examples to illustrate the prin...
The property names often heard in web design: con...
Use the following terminal command to install the...
This article summarizes the common commands for L...
JS calculates the total price of goods in the sho...
System environment: Windows 7 1. Install Docker D...
Recently I want to use goaccess to analyze nginx ...
Table of contents 1. How is cross-domain formed? ...
Step 1: Check the local Ethernet properties to se...
Generally speaking, the mouse is displayed as an u...
The difference between run and start in docker Do...
HTML5 adds a native placeholder attribute for inp...