假设下面四种情况分别用 http://192.168.1.1/proxy/test.html 进行访问。
server { listen 80; server_name example.com; // 接口的域名 // ... location /proxy/ { proxy_pass http://127.0.0.1/; } }
代理到URL:http://127.0.0.1/test.html
server { listen 80; server_name example.com; // 接口的域名 // ... location /proxy/ { proxy_pass http://127.0.0.1; } }
代理到URL:http://127.0.0.1/proxy/test.html
server { listen 80; server_name example.com; // 接口的域名 // ... location /proxy/ { proxy_pass http://127.0.0.1/aaa/; } }
代理到URL:http://127.0.0.1/aaa/test.html
server { listen 80; server_name example.com; // 接口的域名 // ... location /proxy/ { proxy_pass http://127.0.0.1/aaa; } }
代理到URL:http://127.0.0.1/aaatest.html
参考:https://www.jianshu.com/p/b010c9302cd0