nginx指定文件路径有两种方式root和alias
- root:root的处理结果是:root 路径 + location 路径
- alias:alias 的处理结果是:使用 alias路径替换location 路径
注意:alias 后面必须是要用 ‘/’ 结束,不然会找不到文件,root 则不用
eg:
root 案例
location /weather {
root /data/weather-front;
index index.html index.htm;
}
alias 案例
location /weather {
alias /data/weather-front/;
index index.html index.htm;
}
实际开发中可能会遇到一个同时配置多个前端项目的情况,可以参照下方配置根据实际情况进行配置
server{
listen 80;
server_name localhost;
location / {
root html/portal/user;
index index.html index.htm iebdc.html;
}
location /admin {
alias html/portal/admin/;
index index.html index.htm iebdc.html;
}
location /user {
alias html/portal/user/;
index index.html index.htm iebdc.html;
}
}