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

Vue based on Element button permission implementation solution

Background requirements: The ERP system needs to ...

Detailed explanation of how to use the Vue license plate search component

A simple license plate input component (vue) for ...

A detailed discussion of evaluation strategies in JavaScript

Table of contents A chestnut to cover it Paramete...

Vue implements simple data two-way binding

This article example shares the specific code of ...

MySQL 8.0.20 compressed version installation tutorial with pictures and text

1. MySQL download address; http://ftp.ntu.edu.tw/...

Use HTML to write a simple email template

Today, I want to write about a "low-tech&quo...

Example of MySQL slow query

Introduction By enabling the slow query log, MySQ...

Implementation of Docker container connection and communication

Port mapping is not the only way to connect Docke...

Vue implements button switching picture

This article example shares the specific code of ...

What does mysql database do?

MySQL is a relational database management system....

How to remove the header from the element table

Document hints using the show-header attribute sh...

Summary of special processing statements of MySQL SQL statements (must read)

1. Update the entire table. If the value of a col...

Secondary encapsulation of element el-table table (with table height adaptation)

Preface During my internship at the company, I us...