问题描述
该部分笔记将整理:与 Nginx 配置与管理有关的内容。
解决方案
在 Nginx 中,“上游”(Upstream)是指 Nginx 要访问的服务。
重写规则中排除某些URL地址
在Nginx中,进行rewrite跳转,一般的用法是“如果URI匹配表达式,则进行跳转”。
但是,有时也会遇到“如果URI不匹配表达式,则进行跳转”,就是说:大多数URL进行跳转,极个别的URI不进行跳转,可以使用如下的方式:
rewrite ^(?!/(nginx|hadoop|demo)/.+) https://k4nz.com permanent;
这个示例中,除了「/nginx/xxx」「/hadoop/xxx」「/demo/xxx」之外,任何其他的URI都会跳转“https://k4nz.com”%E3%80%82
在Nginx中,当你需要嵌套IF语句,或者IF语句需要多个判断条件时你可能会用到这个。
顺便提一下,解决IF嵌套和多个IF条件的另外一个办法:Nginx how to multiple if statements
配置默认服务器
nginx: how to specify a default server
待完善的部分
# nginx serving alternate location on 404
-「nginx serving alternate location on 404」