Home  >  Article  >  Operation and Maintenance  >  What is the difference between nginx location and proxy_pass

What is the difference between nginx location and proxy_pass

王林
王林forward
2023-05-16 15:16:211293browse

Pre-test access domain name: www.test.com/api/upload

1. Both location and proxy_pass contain /, then the real address does not contain location matching directory

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

Access address :www.test.com/api/upload-->http://127.0.0.1:8080/upload

2. Location does not contain /, proxy_pass contains /, then the real address will contain /

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

Access address: www.test.com/api/upload-->http://127.0.0.1:8080//upload

3.location with /, proxy_pass without /, Then the real address will match the directory /api/

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

with location. Access address: www.test.com/api/upload-->http://127.0.0.1:8080/api/upload

4. Neither location nor proxy_pass contains /, then the real address will contain location to match the directory /api/

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

Access address: www.test.com/api/upload-->http:/ /127.0.0.1:8080/api/upload

5. Same as 1, but proxy_pass takes the address

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

Access address: www.test.com/api/upload-->http: //127.0.0.1:8080/server/upload

6. Same as 2, but proxy_pass has an address, so the real address will be multiple /

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

Access address: www.test.com/ api/upload-->http://127.0.0.1:8080/server//upload

7. Same as 3, but proxy_pass has an address, the real address will be directly connected

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

Access address: www.test.com/api/upload-->http://127.0.0.1:8080/serverupload

8. Same as 4, but proxy_pass has an address, then the real address will match the address Replace the location matching directory

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

Access address: www.test.com/api/upload-->http://127.0.0.1:8080/server/upload

The above is the detailed content of What is the difference between nginx location and proxy_pass. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete