nginx cookie - how to inject variable into cookie
Payam Chychi
pchychi at gmail.com
Tue Jun 2 07:01:51 MSD 2009
On Mon, Jun 1, 2009 at 3:45 AM, Maxim Dounin <mdounin at mdounin.ru> wrote:
> Hello!
>
> On Sun, May 31, 2009 at 02:05:12AM -0700, Payam Chychi wrote:
>
>> Hey,
>>
>> im trying to compare the cookie with the remote_addr via nginx but
>> nginx sees $remote_addr as the text and not the a variable ... so it
>> wont match properly
>> I do have two cookies... the one I need to match for is the 2nd cookie
>> "YPF8827340282Jdskjhfiw_928937459182JAX666=96.48.77.222"
>>
>> if ( $http_cookie !~
>> YPF8827340282Jdskjhfiw_928937459182JAX666=$remote_addr ) {
>> rewrite ^(.*)$ /check/$host.shtml last;
>> break;
>> }
>
> This wont work since nginx doesn't allow variables in a right-hand side
> of the expression. Workaround is to use something like this:
>
> set $blah "$remote_addr:$http_cookie";
> if ($blah !~ "^([0-9.]+):.*YPF8827340282Jdskjhfiw_928937459182JAX666=\1") {
> ...
> }
>
> This uses static pattern with pcre builtin backreference and will
> work as expected.
>
> Maxim Dounin
>
>
Maxim,
Thanks much ... worked out great =)
--
Payam Tarverdyan Chychi
Network Security Specialist / Network Engineer
More information about the nginx
mailing list