1. 程式人生 > 其它 >nginx靜態資源配置

nginx靜態資源配置

root與alias

root會拼接location

alias不會拼接location

例如root

location /static{

    root /home/nginx-1.11.2.4/html/pc/dist;

}

訪問http://127.0.0.1:80/static/abc.pdf

尋找/home/nginx-1.11.2.4/html/pc/dist/static/abc.pdf

例如alias

location /static{

    alias /home/nginx-1.11.2.4/html/pc/dist;

}

訪問http://127.0.0.1:80/static/abc.pdf

尋找/home/nginx-1.11.2.4/html/pc/dist/abc.pdf

proxy_pass

proxy_pass以“/”結尾,不會拼接location後的路徑

proxy_pass不以“/”結尾,會拼接location後的路徑

例1

#訪問地址:http://localhost:8081/model/asc.shtml

#最終代理:http://127.0.0.1:8082/model/asc.shtml

location /model/ {

    proxy_pass   http://127.0.0.1:8082/model/;

}

例2

#訪問地址:http://localhost:8081/model/asc.shtml

#最終代理:http://127.0.0.1:8082/asc.shtml

location /model/ {

    proxy_pass   http://127.0.0.1:8082/;

}

例3

#訪問地址:http://localhost:8081/model/asc.shtml

#最終代理:http://127.0.0.1:8082/AAAmodel/asc.shtml

location /model/ {

    proxy_pass   http://127.0.0.1:8082/AAA;

}

例4

#訪問地址:http://localhost:8081/model/asc.shtml

#最終代理:http://127.0.0.1:8082/asc.shtml

location /model {

    proxy_pass   http://127.0.0.1:8082/;

}