Created
July 15, 2011 16:08
-
-
Save Apkawa/1084981 to your computer and use it in GitHub Desktop.
Nginx hacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Как написать location в nginx, который срабатывает, если два условия должны выполняться. Логично было бы написать так: | |
if ($http_user_agent ~* "Opera" AND $http_referer ~* "yandex.ru") { | |
bla bla bla | |
} | |
nginx не предусматривает в условиях логические операторы | |
Решение есть в виде хака: | |
set $a ""; | |
if ($http_user_agent ~* "Opera" ) { | |
set $a 1; | |
} | |
if ($http_referer ~* "yandex.ru") { | |
set $a 1$a; | |
} | |
if ($a = 11) { | |
bla bla bla | |
} | |
Идея очень проста, создается переменная, в которую по мере срабатывания условий накапливается строка. Далее срабатывает какое-либо условие с учетом этой строки. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment