每次建新项目都会在配nginx时浪费时间,配好之后没留文档记录,导致下次继续浪费时间,今次就书面总结了却顽疾。
1. root
如果用root,若访问location路径,则定位到:root 路径 + location路径,下例中就是:
/usr/local/nginx/test/index.html
location /test {
root /usr/local/nginx;
index index.html index.htm;
}
2. alias (别名)
如果用alias,若访问location路径,则定位到alias路径
location /test {
alias /usr/local/nginx;
index index.html index.htm;
}
//最终路径:usr/local/nginx/index.html
location /test {
alias /usr/local/nginx/test;
index index.html index.htm;
}
//最终路径:usr/local/nginx/test/index.html
location /test2 {
alias /usr/local/nginx/test1;
index index.html index.htm;
}
//访问/test2 , 最终路径:usr/local/nginx/test1/index.html