Detailed explanation of the difference between and and and at the end of url in nginx configuration proxy_pass

  • 2021-09-11 21:50:32
  • OfStack

When nginx configures proxy_pass, the difference between "/" and "/" at the end of url is as follows:

Note: "/" is not allowed at the end of url in proxy_pass when location is a regular expression matching pattern, so the regular expression matching pattern is outside the scope of discussion.

When the end of url in proxy_pass configuration has/, when nginx forwards, the contents of the original uri after removing location matching expression will be spliced after 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/;
}

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/;
}

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/;
}

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/;
}

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

When there is no/at the end of url in proxy_pass configuration, if path is not included in url, the original uri is directly spliced after url in proxy_pass; If path is included in url, the content of the original uri after removing location matching expression is spliced after 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;
 }

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;
}

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;
}

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;
}

Actual access address after proxy: http://192.168. 171.129: 8080/test/tes.jsp


Related articles: