Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx configures the method of shunting according to the terminal segment of the request IP

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

It is mainly the configuration jump judged by if in the location parameters, which can reduce the load and pressure on the server. This is a very common server deployment architecture.

Jump according to the range of the last paragraph of IP

# Domain name, ip, port and other information, please modify upstream huaji-01.com {server 192.168.1.100 upstream huaji-02.com 8080;} upstream huaji-02.com {server 192.168.1.200 server 8080;} server {listen 80; server_name www.huaji.com; location / {if ($remote_addr ~ * ^ (. *)\. [1125] $) {proxy_pass break } proxy_pass http://huaji-02.com;}}

The above is to forward the source of the request with the end segment of IP 1-125to huaji-01.com, and the other to huaji-02.com. You can also modify the rule, such as

Rule: $remote_addr ~ * ^ (. *)\. * [0268] $ends with an even ip such as 0268, jump to huaji-01.com, and others jump to the second domain name

Rule: $remote_addr ~ * ^ (112)\. (. *) $IP starting with 112 jumps to the specified domain name

Rule: $http_x_forwarded_for ~ * ^ (112)\. (. *) $diverts according to the forward address field, and the one starting with 112 jumps to the specified domain name.

The meaning of if instruction condition judgment:

Regular expressions match, where:

~ for case-sensitive matching

~ * for case-insensitive matching

! ~ and! * are case-sensitive mismatch and case-insensitive mismatch, respectively

File and directory match, 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 or not

The last parameter of the rewrite directive is the flag tag, and the flag tag has:

Last is equivalent to the [L] tag in apache and stands for rewrite.

Break after the matching of this rule is completed, the matching is terminated and the subsequent rules are no longer matched.

Redirect returns 302 temporary redirection, and the browser address displays the URL address after the jump.

Permanent returns 301 permanent redirection, and the browser address displays the URL address after the jump.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report