NGINX服务器的反向代理PROXY_PASS配置方法讲解
url的/问题
在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。
四种情况分别用http://IP/proxy/index.html 进行访问
方法1:
location /proxy/ {
proxy_pass http://127.0.0.1:8000/;
}
代理地址:网站目录/index.html
访问地址:IP/proxy/index.html
方法二:
location /proxy/ {
proxy_pass http://127.0.0.1:8000;
}
代理地址:网站目录/proxy/index.html
访问地址:IP/proxy/index.html
方法三:
location /proxy/ {
proxy_pass http://127.0.0.1:8000/proxy/;
}
代理地址:网站目录/proxy/index.html
访问地址:IP/proxy/index.html
方法四:
location /proxy/ {
proxy_pass http://127.0.0.1:8000/proxy;
}
代理地址:网站目录/proxy+访问文件名
访问地址:IP/proxy/index.html
每个结果都通过日志查看并给出具体的代理地址、访问地址;希望不要踩坑(浪费时间!)根据需求选择对应的代理方式

浙公网安备 33010602011771号