Detailed explanation of various usages of proxy_pass in nginx

Detailed explanation of various usages of proxy_pass in nginx

Proxy forwarding rules

When configuring location proxy forwarding rules in nginx, different writing methods correspond to different forwarding rules.

If proxy_pass uses a URI, when the request is transmitted to the backend server, the matching part of the normalized request path and the path in the configuration will be replaced by the URI defined in the directive (corresponding to the first case below).

If proxy_pass is not used with a URI, the request URI sent to the backend server is generally the original URI initiated by the client (the second case below).

Access address: http://localhost/proxy/abc.html

Here are some common matching scenarios:

The first one:

location /proxy/ {
proxy_pass http://127.0.0.1:8080/;
}

Proxy to: http://127.0.0.1:8080/abc.html

Second type:

location /proxy/ {
proxy_pass http://127.0.0.1:8080;
}

Compared with the first proxy_pass, it lacks /
Proxy to: http://127.0.0.1:8080/proxy/abc.html

The third type:

location /proxy/ {
proxy_pass http://127.0.0.1:8080/api/;
}

Proxy to: http://127.0.0.1:8080/api/abc.html

The fourth type:

location /proxy/ {
proxy_pass http://127.0.0.1:8080/api;
}

Less than the third type/
Proxy to: http://127.0.0.1:8080/apiabc.html

location /proxy {
proxy_pass http://127.0.0.1:8080/api;
}

Proxy to: http://127.0.0.1:8080/api/abc.html

Fifth:

location /proxy {
proxy_pass http://127.0.0.1:8080/;
}

Proxy to: http://127.0.0.1:8080//abc.html
Note that there are two backslashes //

location /proxy {
proxy_pass http://127.0.0.1:8080;
}

Proxy to: http://127.0.0.1:8080/proxy/abc.html

Here is an explanation from the official documentation:

httpproxy

NGINX-httpproxy module official documentation Chinese documentation translated by Alibaba tengine - recommended reading

This is the end of this article about the various uses of proxy_pass in nginx. For more relevant content on the use of nginx proxy_pass, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Summary of Nginx location and proxy_pass path configuration issues
  • Detailed explanation of the difference between url ending with / and without / in nginx proxy_pass configuration
  • Proxy_pass method in multiple if in nginx location
  • Implementation of proxy_pass in nginx reverse proxy
  • Differences between proxy_pass in two modules in nginx

<<:  CSS3 realizes bouncing ball animation

>>:  html opens a new window with a hyperlink and can control window properties

Recommend

Vue implements scrollable pop-up window effect

This article shares the specific code of Vue to a...

Automated front-end deployment based on Docker, Nginx and Jenkins

Table of contents Preliminary preparation Deploym...

HTML head tag detailed introduction

There are many tags and elements in the HTML head ...

32 Typical Column/Grid-Based Websites

If you’re looking for inspiration for columnar web...

Win10 install Linux ubuntu-18.04 dual system (installation guide)

I installed a Linux Ubuntu system on my computer....

MySQL5.7.21 decompressed version installation detailed tutorial diagram

Since I often install the system, I have to reins...

Gallery function implemented by native Js

Table of contents The first The second Native Js ...

Summary of using MySQL online DDL gh-ost

background: As a DBA, most of the DDL changes of ...

Detailed explanation of the error problem of case when statement

Preface In the MySQL database, sometimes we use j...

Native JS to implement click number game

Native JS implements the click number game for yo...

Several important MySQL variables

There are many MySQL variables, some of which are...

IE6 distortion problem

question: <input type="hidden" name=...