1、root:

root配置代理路径时,会在代理的地址后拼接配置字段:

location /static {
root static/image;
}

在访问​​http://ip​​:port/static/.时会映射到http://ip​:port/static/static/image/.

2、alias(只能用于location):

alias配置代理路径时,直接替换代理地址:

location /static {
root static/image;
}

在访问​​http://ip​​:port/static/.时会映射到http://ip​:port/static/image/.

3、proxy_pass:

假设下面四种情况分别用 ​​http://192.168.1.1/proxy/test.html​​ 进行访问。

第一种:
location /proxy/ {
proxy_pass http://127.0.0.1/;
}
代理到URL:http://127.0.0.1/test.html

第二种(相对于第一种,最后少一个 / )
location /proxy/ {
proxy_pass http://127.0.0.1;
}
代理到URL:http://127.0.0.1/proxy/test.html

第三种:
location /proxy/ {
proxy_pass http://127.0.0.1/aaa/;
}
代理到URL:http://127.0.0.1/aaa/test.html

第四种(相对于第三种,最后少一个 / )
location /proxy/ {
proxy_pass http://127.0.0.1/aaa;
}
代理到URL:http://127.0.0.1/aaatest.html