Nginx routing forwarding and reverse proxy location configuration implementation

Nginx routing forwarding and reverse proxy location configuration implementation

Three ways to configure Nginx

The first method directly replaces the location matching part

The second proxy_pass target address does not have a / by default, which means that only the proxy domain name is used, and the url and parameter parts will not change (the requested path is concatenated with the proxy_pass target domain name as the proxy URL)

The third type of proxy_pass target address adds a / after it, which means that the part of the path that successfully matches the location is cut off and then spliced ​​into the proxy_pass target address.

Location configuration

location [ = | ~ | ~* | ^~ ] uri {...}

The content in square brackets before uri is optional and is explained as follows:

  • "=": used before the standard URI, requiring the request string to strictly match the URI, and stopping once the match is successful
  • "~": used before the regular uri and is case-sensitive
  • "~*": used before the regular uri, but not case-sensitive
  • "^~": used before the standard URI, requiring Nginx to find the location with the highest match between the URI and the request string, and immediately use this location to process the request, instead of using the regular URI in the location block to match the request string.

symbol meaning
= Exact Match
^~ Non-regular matching
~ Regular expression matching (case sensitive)
~* Regular expression matching (case insensitive)
!~ Regular expression does not match (case sensitive)
!~* Regular expression does not match (case insensitive)
Normal matching (when there is no symbol here)

example

For example, the following configuration demonstrates the third configuration scheme. When we visit http://44.179.118.54:80/shop/xxx

When accessing, Nginx will intercept /shop/ and then concatenate the following path to proxy_pass

Then what we actually visit is: http://44.179.118.54:8007/xxx this service

 #shop-service
 # Reverse proxy shop-service service location ^~ /shop/ {
     #proxy_redirect off;
     #proxy_connect_timeout 60;
     #proxy_read_timeout 60;
     #proxy_send_timeout 60;
     #proxy_buffer_size 4k;
     #proxy_buffers 4 32k;
     #proxy_busy_buffers_size 64k;
     #proxy_temp_file_write_size 64k;
     #proxy_max_temp_file_size 128m;
     proxy_pass http://44.179.118.54:8007/;
     #proxy_set_header X-Real-IP $remote_addr;

     #root /var/www/test/user/
     #index index.html
     #proxy_pass https://www.baidu.com;
 }

This is the end of this article about Nginx routing forwarding and reverse proxy location configuration implementation. For more related Nginx routing forwarding and reverse proxy content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Nginx application location routing reverse proxy and rewrite strategy example
  • Nginx configures the location module to implement routing (reverse proxy, redirection) functions

<<:  HTML head structure

>>:  Overview and application of position attributes (absolute|relative|static|fixed) in CSS

Recommend

Detailed explanation of the difference between docker-compose ports and expose

There are two ways to expose container ports in d...

Steps to create your own YUM repository

To put it simply, the IP of the virtual machine u...

Vue+echarts realizes progress bar histogram

This article shares the specific code of vue+echa...

Summary of Linux command methods to view used commands

There are many commands used in the system, so ho...

A brief discussion on the magic of parseInt() in JavaScript

cause The reason for writing this blog is that I ...

Tutorial on installing Ceph distributed storage with yum under Centos7

Table of contents Preface Configure yum source, e...

Apache ab concurrent load stress test implementation method

ab command principle Apache's ab command simu...

Example of how to set automatic creation time and modification time in mysql

This article describes how to set the automatic c...

Summary of 7 pitfalls when using react

Table of contents 1. Component bloat 2. Change th...

uniapp dynamic modification of element node style detailed explanation

Table of contents 1. Modify by binding the style ...

Issues installing Python3 and Pip in ubuntu in Docker

text 1) Download the Ubuntu image docker pull ubu...

Detailed explanation of keepAlive use cases in Vue

In development, it is often necessary to cache th...

How to change the root password of Mysql5.7.10 on MAC

First, start MySQL in skip-grant-tables mode: mys...