- server {
- listen 80;
- server_name localhost;
-
- # 访问 http://localhost:80/ 时,转发到http://localhost:10001/
- location / {
- proxy_pass http://localhost:10001/;
- }
-
- # 访问 http://localhost:80/gateway/ 时,转发到http://localhost:10000/
- location /gateway/ {
- proxy_pass http://localhost:10000/;
- }
-
- }
以访问http://localhost:10000/gateway/为例:
一、如果最后多一个 /,会被转发到http://localhost:10000/
例:api是http://localhost/gateway/xxx,转发后为http://localhost/xxx
- location /gateway/ {
- proxy_pass http://localhost:10000/;
- }
二、如果最后少一个 /,会被转发到http://localhost:10000/gateway/
例:api是http://localhost/gateway/xxx,转发后为http://localhost/gateway/xxx
- location /gateway/ {
- proxy_pass http://localhost:10000;
- }
三、如果加上path,且最后多一个 /,会被转发到http://localhost:10000/gateway/
例:api是http://localhost/gateway/xxx,转发后为http://localhost/gateway/xxx
- location /gateway/ {
- proxy_pass http://localhost:10000/gateway/;
- }
四、如果加上path,且最后少一个 /,会被转发到http://localhost:10000/gateway
例:api是http://localhost/gateway/xxx,转发后为http://localhost/gatewayxxx
- location /gateway/ {
- proxy_pass http://localhost:10000/gateway;
- }