#第一种: proxy_pass中带/
location /api
{
proxy_pass http://127.0.0.1/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#请求:http://localhost/api/location
#代理:http://127.0.0.1/location
#第二种: proxy_pass中不带/
location /api
{
proxy_pass http://127.0.0.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#请求:http://localhost/api/location
#代理:http://127.0.0.1/api/location
总结: proxy_pass请求末尾带上‘/’,相当于提供自动“rewrite”功能