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

...

Detailed explanation of the failure of MySQL to use UNION to connect two queries

Overview UNION The connection data set keyword ca...

Install MySQL 5.7.18 using rpm package under CentOS 7

I have been using MySQL recently. The article mys...

How to avoid duplication of data when inserting in MySql batch

Table of contents Preface 1. insert ignore into 2...

If I change a property randomly in Vue data, will the view be updated?

Interviewer: Have you read the source code of Vue...

Docker installation and configuration image acceleration implementation

Table of contents Docker version Install Docker E...

Mysql command line mode access operation mysql database operation

Usage Environment In cmd mode, enter mysql --vers...

Implementing search box function with search icon based on html css

Preface Let me share with you how to make a searc...

Dockerfile implementation code when starting two processes in a docker container

I want to make a docker for cron scheduled tasks ...

How to query the latest transaction ID in MySQL

Written in front: Sometimes you may need to view ...

Linux/Mac MySQL forgotten password command line method to change the password

All prerequisites require root permissions 1. End...

How to use axios to make network requests in React Native

In front-end development, there are many ways to ...