nginx location root alias 用法说明

一、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错误。

以上配置中,结尾可以加“/”,也可以不加。

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...