使用 if 关键字
Module ngx_http_rewrite_module
NGINX not equal to – Stack Overflow
# 判断变量是否匹配字符串 if ($var != CN) { return 444; } if ($var = EN) { return 200; }
使用变量
Alphabetical index of variables
reverse proxy – nginx – read custom header from upstream server – Stack Overflow
通过 $http_<header-field> 形式,y以此引用请求头的字段。比如:
1)$http_user_agent:获取请求头的 User-Agent 字段;
2)$http_x_real_ip:引用请求头的 X-Real-IP 字段;
在字符串中使用环境变量:
1)set $foobar "${foo}bar";
配置文件生成工具
digitalocean/nginxconfig.io: ⚙️ NGINX config generator on steroids 💉
演示站点:NGINX Config | DigitalOcean
nginx – Merging variable with string in config file – Server Fault