1、root和alias
root:root电商商城定制开发指定的目录是上级目录,path电商商城定制开发匹配的整个路径会追加,即root+path;
alias:alias指定的目录必须带/,path匹配后面的内容会在alias指定的目录下查找,即alias+匹配到path路径后面的部分。
例:
location /www/ {
root /home/data;
}
访问路径:http://www.abc.com/www/a.html,实际上是访问/home/data/www/a.html。
location /www/ {
alias /home/data;
}
访问路径:http://www.abc.com/www/a.html,实际上是访问/home/data/a.html。
2、proxy_pass的斜杠问题
1)path没有斜杠
location /api1 { proxy_pass http://localhost:8080; }
# http://localhost/api1/xxx -> http://localhost:8080/api1/xxx
location /api2 { proxy_pass http://localhost:8080/; }
# http://localhost/api2/xxx -> http://localhost:8080/xxx
location /api5 { proxy_pass http://localhost:8080/haha; }
# http://localhost/api5/xxx -> http://localhost:8080/haha/xxx,请注意这里的这里的双斜线。
2)path有斜杠
location /api1/ { proxy_pass http://localhost:8080; }
# http://localhost/api1/xxx -> http://localhost:8080/api1/xxx
location /api2/ { proxy_pass http://localhost:8080/; }
# http://localhost/api2/xxx -> http://localhost:8080/xxx
location /api5/ { proxy_pass http://localhost:8080/haha; }
# http://localhost/api5/xxx -> http://localhost:8080/hahaxxx,请注意这里的haha和xxx之间没有斜杠。
总结:
path有无斜杠无影响,主要看proxy_pass有没有斜杠。proxy_pass没有的话,proxy_pass+path;有的话(包括端口和上下文都是一样的),proxy_pass+匹配到path路径后面的部分。