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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值