nginx 转发配置
proxy_pass
假设下面四种情况分别用 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;
}
}