一、alias
location /view {
alias /opt/view;
index index.html index.htm;
access_log on;
expires 30d;
}
alias 是目录别名的意思,指的是绝对路径。
因此按照以上配置的话,如果请求路径是 /view/hello.html,则nginx会去目录/opt/view下找文件hello.html。找不到则报404错误。
二、root
1、
location /view {
root /opt;
index index.html index.htm;
access_log on;
expires 30d;
}
2、
location /view/test {
root /opt;
index index.html index.htm;
access_log on;
expires 30d;
}
root是最上层目录的意思, 指的是相对路径,即相对访问路径的目录。
因此按照以上第一种情况配置的话,如果请求路径是 /view/hello.html,则nginx会去目录/opt/view下找文件hello.html;按照第二种情况配置的话,如果请求路径是 /view/test/hello.html,则nginx会去目录/opt/view/test下找文件hello.html。找不到则报404错误。
以上配置中,结尾可以加“/”,也可以不加。