nginx的proxy_pass后的最后加/和不加/的区别(最好最后都加/)
假设server_name为www.aminglinux.com,当请求http://www.aminglinux.com/aming/a.html的时候
示例1:
location /aming/
{
proxy_pass http://192.168.1.10; #如果不加/(网站根目录),那么访问,不会带/,访问的地址会带上自己/aming
#访问的最终结果为:http://192.168.1.10/aming/a.html
...
}
示例2:
location /aming/
{
proxy_pass http://192.168.1.10/; #如果加了/(网站根目录),就会带/,就会访问以/(网站根目录)开头的地址进行访问
#访问的最终结果为:http://192.168.1.10/a.html
...
}
示例3:
location /aming/
{
proxy_pass http://192.168.1.10/linux/; #如果加了/,访问就会带/
#访问最终结果为:http://192.168.1.10/linux/a.html
...
}
示例4:
location /aming/
{
proxy_pass http://192.168.1.10/linux; #如果不加/,则访问也不会带/
#访问最终结果为:http://192.168.1.10/linuxa.html
...
}
建议:不论什么情况都加上最后的/为好,都是以代理后的地址的最后/为匹配。