一、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错误。
以上配置中,结尾可以加“/”,也可以不加。
原文地址:https://blog.csdn.net/thlzjfefe" target="_blank" rel="noopener" title="thlzjfefe">thlzjfefe</a> <img class="article-time-img article-heard-img" src="https://csdnimg.cn/release/blo
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。