nginx同一个server下配置多套前端页面

因同一个server下location root只能配置一个,此时需要使用虚拟目录alias。
location /mobile/ {
alias /home/mobile/
try_files $uri $uri/ /mobile/index.html;
}
这样配置当访问的/mobile/下资源不存在时会跳转到/mobile/index.html。

try_file简单介绍

一.try_files的语法规则:

格式1:try_files file … uri; 格式2:try_files file … =code;

可应用的上下文:server,location段

二.举例说明:

location /images/ {
root /opt/html/;
try_files $uri $uri/ /images/default.gif;
}
比如 请求 127.0.0.1/images/test.gif 会依次查找
1.文件/opt/html/images/test.gif
2.文件夹 /opt/html/images/test.gif/下的index文件
3. 请求127.0.0.1/images/default.gif

三.其他注意事项
1.try-files 如果不写上 $uri/,当直接访问一个目录路径时,并不会去匹配目录下的索引页 即 访问127.0.0.1/images/ 不会去访问 127.0.0.1/images/index.html

四.其他用法
location / {
try_files /system/maintenance.html
$uri $uri/index.html $uri.html
@mongrel;
}

location @mongrel {
proxy_pass http://mongrel;
}

以上中若未找到给定顺序的文件,则将会交给location @mongrel处理(相当于匹配到了@mongrel来匹配)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值