Nginx对指定目录做代理

Posted by     Airmole on February 19, 2018

环境介绍

web1,作为前端服务器,访问地址是http://192.168.1.1,要将http://192.168.1.1/bbs的请求交给web2。在web1的网站根目录下并没有bbs目录。 web2,作为后端web服务器,访问地址是http://192.168.1.2

web1配置location 方式一

location /bbs/ {
proxy_pass http://192.168.1.2/;             #有“/”
}

实现效果:通过 http://192.168.1.1/bbs 可以访问到web2网站根目录下的内容

web1配置location 方式二

如果在web1的location中少加 “/”

location /bbs/ {
proxy_pass http://192.168.1.2;            #无“/”
}

实现效果:要通过web1反问web2网站根目录的内容则需要输入:http://192.168.1.1/bbs/bbs

<font color=#394959 size=12>测试</font>