Detailed explanation of the difference between url ending with / and without / in nginx proxy_pass configuration

Detailed explanation of the difference between url ending with / and without / in nginx proxy_pass configuration

When nginx configures proxy_pass, the difference between the URL with "/" at the end and without "/" at the end is as follows:

Note: When location is a regular expression matching pattern, the URL in proxy_pass is not allowed to have a "/" at the end, so the regular expression matching pattern is not within the scope of discussion.

When the URL in the proxy_pass configuration ends with a /, when nginx forwards, it will remove the location matching expression from the original URI and append it to the URL in proxy_pass.

Test address: http://192.168.171.129/test/tes.jsp

Scenario 1:

location ^~ /test/ {
 proxy_pass http://192.168.171.129:8080/server/;
}

The actual access address after proxy: http://192.168.171.129:8080/server/tes.jsp

Scenario 2:

location ^~ /test {
 proxy_pass http://192.168.171.129:8080/server/;
}

The actual access address after proxy: http://192.168.171.129:8080/server//tes.jsp

Scenario 3:

location ^~ /test/ {
 proxy_pass http://192.168.171.129:8080/;
}

The actual access address after proxy: http://192.168.171.129:8080/tes.jsp

Scenario 4:

location ^~ /test {
 proxy_pass http://192.168.171.129:8080/;
}

The actual access address after proxy: http://192.168.171.129:8080//tes.jsp

When there is no / at the end of the URL in the proxy_pass configuration, if the URL does not contain path, the original URI is directly concatenated after the URL in proxy_pass; if the URL contains path, the original URI is concatenated after removing the location matching expression and the URL in proxy_pass.

Test address: http://192.168.171.129/test/tes.jsp

Scenario 1:

 location ^~ /test/{
 proxy_pass http://192.168.171.129:8080/server;
 }

The actual access address after proxy: http://192.168.171.129:8080/servertes.jsp

Scenario 2:

location ^~ /test {
 proxy_pass http://192.168.171.129:8080/server;
}

The actual access address after proxy: http://192.168.171.129:8080/server/tes.jsp

Scenario 3:

location ^~ /test/ {
 proxy_pass http://192.168.171.129:8080;
}

The actual access address after proxy: http://192.168.171.129:8080/test/tes.jsp

Scenario 4:

location ^~ /test {
 proxy_pass http://192.168.171.129:8080;
}

The actual access address after proxy: http://192.168.171.129:8080/test/tes.jsp

This concludes this article on the differences between nginx proxy_pass with and without the end of the URL. For more information about the end of the nginx proxy_pass URL, please search 123WORDPRESS.COM's previous articles or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of various usages of proxy_pass in nginx
  • Summary of Nginx location and proxy_pass path configuration issues
  • 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

<<:  Detailed explanation of Object.create instance usage in js

>>:  In-depth understanding of HTML form input monitoring

Recommend

MySQL functional index optimization solution

When using MySQL, many developers often perform f...

Simple Implementation of HTML to Create Personal Resume

Resume Code: XML/HTML CodeCopy content to clipboa...

Tutorial on upgrading from Centos7 to Centos8 (with pictures and text)

If you upgrade in a formal environment, please ba...

Introduction to Docker containers

Docker Overview Docker is an open source software...

40 web page designs with super large fonts

Today's web designs tend to display very larg...

Detailed explanation of Docker daemon security configuration items

Table of contents 1. Test environment 1.1 Install...

Detailed explanation of CSS elastic box flex-grow, flex-shrink, flex-basis

The functions of the three attributes flex-grow, ...

Example code for implementing 3D text hover effect using CSS3

This article introduces the sample code of CSS3 t...

Solve the problem of using less in Vue

1. Install less dependency: npm install less less...

Implementation of debugging code through nginx reverse proxy

background Now the company's projects are dev...

Troubleshooting MySQL high CPU load issues

High CPU load caused by MySQL This afternoon, I d...

Simple web page code used in NetEase blog

How to use the code in NetEase Blog: First log in...