【发布时间】:2021-09-21 05:04:02
【问题描述】:
我有这样的 NGINX 配置
server {
listen 80;
server_name localhost;
#any request without the http cookie has to be redirected to login
location / {
if ($http_cookie ~* "user_tokens") {
return 302 http://127.0.0.0:5000/;
#break;
}
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
想法是像配置路由规则
- 任何没有 cookie 的请求都会重定向到登录服务器 (5000)。
- 否则它应该服务于根目录中的页面。
但这并没有按预期工作,它总是从根目录提供页面。
【问题讨论】:
-
在
$http_cookie不包含user_tokens的情况下使用!~*。