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

What is the difference between nginx location and proxy_pass

王林
Release: 2023-05-16 15:16:21
forward
1427 people have browsed it

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/;
}
Copy after login

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/;
}
Copy after login

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;
}
Copy after login

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;
}
Copy after login

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/;
}
Copy after login

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/;
}
Copy after login

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;
}
Copy after login

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;
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template