1
Phant0m 2016-12-20 00:25:26 +08:00 via iPhone
ngx lua 可以实现
|
2
lhbc 2016-12-20 00:54:49 +08:00
map $COOKIE_abc
|
3
shiniv 2016-12-20 01:29:48 +08:00
试试这样能能否符合你的需求
set $auth_cookie 0; if ($http_cookie ~* "AUTH_COOKIE=([a-z0-9]+)(?:/|$)") { set $auth_cookie 1; } if ($auth_cookie = 0) { return 403; } |
4
jarlyyn 2016-12-20 01:39:47 +08:00 2
location / {
if ( $cookie_antiscanpassword != "password") { return 403; } proxy_pass http://127.0.0.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } http://blog.jarlyyn.com/site/blogi/100-%E7%94%A8nginx%2Bcookie%E9%98%B2%E6%AD%A2%E7%AE%80%E5%8D%95%E7%9A%84%E6%8A%93%E5%8F%96%2F%E7%A0%B4%E8%A7%A3%E9%AA%9A%E6%89%B0 我线上在用的 |
5
nikoo OP |
7
nikoo OP @jarlyyn
if ( $cookie_antiscanpassword != "password") { 这句是判断名为 antiscanpassword 的 cookie 值是否为 "password" 吧?而不是判断 antiscanpassword 是否存在 |
8
jarlyyn 2016-12-20 10:05:46 +08:00
@nikoo
应该是直接 if ( $cookie_antiscanpassword),不行的话正则处理 if ( $cookie_antiscanpassword~ .+) 参考 http://nginx.org/en/docs/http/ngx_http_rewrite_module.html a variable name; false if the value of a variable is an empty string or “ 0 ”; Before version 1.0.1, any string starting with “ 0 ” was considered a false value. comparison of a variable with a string using the “=” and “!=” operators; matching of a variable against a regular expression using the “~” (for case-sensitive matching) and “~*” (for case-insensitive matching) operators. Regular expressions can contain captures that are made available for later reuse in the $1..$9 variables. Negative operators “!~” and “!~*” are also available. If a regular expression includes the “}” or “;” characters, the whole expressions should be enclosed in single or double quotes. checking of a file existence with the “-f ” and “!-f ” operators; checking of a directory existence with the “-d ” and “!-d ” operators; checking of a file, directory, or symbolic link existence with the “-e ” and “!-e ” operators; checking for an executable file with the “-x ” and “!-x ” operators. |
9
AlexaZhou 2016-12-20 11:20:10 +08:00
不想太麻烦的话,可以试试 VeryNginx
|