In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This paper introduces the sample code to achieve IP access diversion through Nginx reverse proxy and share it with you. The details are as follows:
It is a common server deployment architecture to achieve shunting through Nginx as a reverse proxy to reduce the load and pressure on the server. This article will share a method of how to divert according to the source IP.
Shunting according to a specific IP
Forward the last segment of the IP address whose last bit is 0 or 2 or 6 to test-01.com for execution, otherwise forward to test-02.com for execution.
Upstream test-01.com {server 192.168.1.100 upstream test-02.com {server 192.168.1.200 upstream test-02.com 8080;} server {listen 80; server_name www.test.com; location / {if ($remote_addr ~ * ^ (. *)\. * [026] $) {proxy_pass break;} proxy_pass http://test-02.com;}}
Forward the first three segments of the IP address 192.168.202.* to test-01.com for execution, otherwise forward to test-02.com for execution.
Upstream test-01.com {server 192.168.1.100 upstream test-02.com {server 192.168.1.200 upstream test-02.com 8080;} server {listen 80; server_name www.test.com; location / {if ($remote_addr ~ * ^ (192)\. (168)\. (202)\. (. *) $) {proxy_pass break;} proxy_pass http://test-02.com;}
Shunting according to the specified range of IP
The last segment of the IP address is forwarded to test-01.com for execution, otherwise it is forwarded to test-02.com for execution.
Upstream test-01.com {server 192.168.1.100 upstream test-02.com {server 192.168.1.200 upstream test-02.com 8080;} server {listen 80; server_name www.test.com; location / {if ($remote_addr ~ * ^ (. *)\. [1100] $) {proxy_pass break;} proxy_pass http://test-02.com;}}
Offload based on forwarded addr
The access at the beginning of the first paragraph of the IP address is forwarded to test-01.com for execution, otherwise forwarded to test-02.com for execution.
Upstream test-01.com {server 192.168.1.100 upstream test-02.com {server 192.168.1.200 upstream test-02.com 8080;} server {listen 80; server_name www.test.com; location / {if ($http_x_forwarded_for ~ * ^ (212)\. (. *) $) {proxy_pass break;} proxy_pass http://test-02.com;}}
The function of if instruction
If instruction: determines whether the value of the expression is true (true), and if so, executes the following curly braces.
Here are some common ways to compare conditional expressions:
Complete comparisons of variables can be done using the = or! = operator partial matching can be expressed using regular expressions of ~ or ~ * to indicate case sensitivity ~ * to indicate case insensitivity (nginx is the same as Nginx)! ~ and! ~ * are inverted operations Check for the existence of a file using the-f or!-f operator to check for the existence of a directory. Use the-d or!-d operator to check for the existence of a file, directory, or symbolic link. Use the-e or!-e operator to check whether a file is executable. Partial matching of regular expressions using the-x or!-x operators can use parentheses, and the matching can be replaced by the $1qq9 variable.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.