Detailed explanation of nginx front-end distribution method based on $remote_addr

Detailed explanation of nginx front-end distribution method based on $remote_addr

The requirements are as follows:

There are multiple servers under the domain name. Now we are testing a certain region. Let the IP users in a certain region access only one server and test it separately. If there is no problem, all servers will be updated. If there is a problem, the impact will be small. We will find and solve the problem in time.

Solution:

Use the nginx module to configure matching rules on the front-end load balancing forwarding machine;

In the nginx configuration vhost, add a piece of code to the location section under the domain name

If $remote_addr matches the ip, forward it to abc_test_server;

server {
  listen 80;
  server_name abc.com.cn;
  access_log /dev/null;
  error_log /data/logs/error.log;
  
  location / {

  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      if ($remote_addr ~ "202.96.134.100") 
       {
           proxy_pass http://abc_test_server;
            break;
        }
  proxy_pass http://abc_server;
  }
}

The load balancing configuration also needs to add a section

#abc_test only
upstream abc_test_server {
  server 192.168.20.10:80;
  
}

#abc.com.cn
upstream abc_server {
  server 192.168.20.11:80;
  server 192.168.20.12:80;
  server 192.168.20.13:80;
}

The set IP will be directly distributed to the backend server 192.168.20.10 for testing;

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:
  • Detailed explanation of Nginx configuration required for front-end
  • How to use Nginx to solve front-end cross-domain problems
  • Nginx configuration for front-end development (scenario)
  • Several methods of deploying multiple front-end projects with nginx
  • Detailed explanation of how Nginx solves the problem of cross-domain access to front-end resources
  • Detailed explanation of what nginx can do on the front end

<<:  Node+express to achieve paging effect

>>:  MySQL Server 8.0.13.0 Installation Tutorial with Pictures and Text

Recommend

MySQL 5.7.24 installation and configuration method graphic tutorial

MySQL is the most popular relational database man...

Docker case analysis: Building a Redis service

Table of contents 1 Create mount directories and ...

Bootstrap 3.0 study notes page layout

This time we will mainly learn about layout, whic...

How to create https using nginx and Tencent Cloud free certificate

I have been studying how to get https. Recently I...

Mysql join query syntax and examples

Connection query: It is the result of connecting ...

MySQL 20 high-performance architecture design principles (worth collecting)

Open Source Database Architecture Design Principl...

A brief discussion on React native APP updates

Table of contents App Update Process Rough flow c...

Vue implements small form validation function

This article example shares the specific code of ...

Analysis of Linux configuration to achieve key-free login process

1.ssh command In Linux, you can log in to another...

HTML Tutorial: DOCTYPE Abbreviation

When writing HTML code, the first line should be ...

MySQL scheduled backup solution (using Linux crontab)

Preface Although some love in this world has a pr...

Detailed explanation of the loop form item example in Vue

Sometimes we may encounter such a requirement, th...

Detailed example of HTML element blocking Flash

Copy code The code is as follows: wmode parameter...

Guide to using env in vue cli

Table of contents Preface Introduction-Official E...