Welcome! Log In Create A New Profile

Advanced

nginx config question, rules?

Posted by TPFreak 
nginx config question, rules?
May 07, 2015 03:38PM
This works:
add_header Set-Cookie "EXAMPLE=$SHAIP;Path=/";

This does not work:
if ($http_cookie ~ "EXAMPLE=$SHAIP") {

Why this? How can I get it to work? I want $SHAIP to be checked if exist, basically it will store the cookie if its not set already.

This is what shaip is:
set_sha1 $SHAIP test;

i want it to compare the sha1'd "test" text, if the cookie is set or not.. for some reason i cant put that variable there?

it's a little hard to explain.

if ($http_cookie ~ "EXAMPLE=$SHAIP") {
return 403;
}

How will i do this correctly? basically check if the sha1'd cookie is set.. currently it just checks if that variable is set, instead of the sha1 its elf.



Edited 1 time(s). Last edit at 05/07/2015 03:39PM by TPFreak.
Re: nginx config question, rules?
May 08, 2015 01:11PM
if ($http_cookie ~ "EXAMPLE=$SHAIP") {


this is the issue, i cant use variable after = or so, how would i do this?
Re: nginx config question, rules?
May 08, 2015 01:54PM
Something with map,

http://serverfault.com/questions/268633/controlling-nginx-proxy-target-using-a-cookie

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: nginx config question, rules?
May 08, 2015 04:04PM
itpp2012 Wrote:
-------------------------------------------------------
> Something with map,
>
> http://serverfault.com/questions/268633/controlling-nginx-proxy-target
> -using-a-cookie


I don't understand you? I wonder why I can't put a variable in the cookie check, and how I can. Can someone give me a snippet?
Re: nginx config question, rules?
May 08, 2015 04:25PM
Read that page, its more or less the same issue which should be solved with a map block, then use a single IF inside a location block.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: nginx config question, rules?
May 09, 2015 08:09AM
itpp2012 Wrote:
-------------------------------------------------------
> Read that page, its more or less the same issue which should be solved
> with a map block, then use a single IF inside a location block.


yes i did

i tried putting it inside the map, didnt detect it for some reason
Re: nginx config question, rules?
May 09, 2015 10:39AM
Did you enclosed them with "" (double quotes) ?

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: nginx config question, rules?
May 09, 2015 04:02PM
map $http_cookie $checkCookie {
default false;
$SHA1 true;
}

tried this, not sure how to do it properly with the cookies.
Re: nginx config question, rules?
May 09, 2015 04:52PM
map $http_cookie $checkCookie {
default 0;
~$SHA1 1;
}

Then inside a location block:

if ($checkCookie) { return 403; } # or whatever you want to happen instead of a 403

If you want to allow things when $SHA1 is filled then turn the 0 and 1 around in the map.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: nginx config question, rules?
May 10, 2015 04:03AM
itpp2012 Wrote:
-------------------------------------------------------
> map $http_cookie $checkCookie {
> default 0;
> ~$SHA1 1;
> }
>
> Then inside a location block:
>
> if ($checkCookie) { return 403; } # or whatever you want to happen
> instead of a 403
>
> If you want to allow things when $SHA1 is filled then turn the 0 and 1
> around in the map.


Thanks, but wouldn't i need to store the cookie like this?

CookieName=CookiueValue

in my case

CookieName=$SHA1
Re: nginx config question, rules?
May 10, 2015 05:16AM
With map it depends what your testing for and when a test is positive what you want to be in the mapped variable, for example;

map $http_user_agent $mobile {
default 0;
"~Opera Mini" 1;
}

If the $http_user_agent contains the string portion "*Opera Mini*" then $mobile will be set to the value 1.

Later on in a location block you can use $mobile and do something based on its value.

I think you first should think about what you want to test for with map and what kind of result you want to store in a variable and then think how you want to use this variable in a location block.

Even if you write some code nginx isn't accepting, because you wrote it down, we can think of a way how it should work.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: nginx config question, rules?
May 10, 2015 05:34PM
itpp2012 Wrote:
-------------------------------------------------------
> With map it depends what your testing for and when a test is positive
> what you want to be in the mapped variable, for example;
>
> map $http_user_agent $mobile {
> default 0;
> "~Opera Mini" 1;
> }
>
> If the $http_user_agent contains the string portion "*Opera Mini*"
> then $mobile will be set to the value 1.
>
> Later on in a location block you can use $mobile and do something
> based on its value.
>
> I think you first should think about what you want to test for with
> map and what kind of result you want to store in a variable and then
> think how you want to use this variable in a location block.
>
> Even if you write some code nginx isn't accepting, because you wrote
> it down, we can think of a way how it should work.


uhm i dont understand you completly....

this is just a normal mapping right? i need a map with normal string and one variable,

if ($http_cookie ~ "EXAMPLE=$SHAIP") {

like this, just working

example= is the string
$SHAIP is the variable..



Edited 1 time(s). Last edit at 05/10/2015 05:38PM by TPFreak.
Re: nginx config question, rules?
May 10, 2015 05:54PM
why wouldnt this work



set_sha1 $SHA1Cookie test;
set $TEST33 TechPulse_Firewall=$SHA1Cookie;

if ($http_cookie ~ $TEST33) {
set $l7_protect 1;
}
Re: nginx config question, rules?
May 10, 2015 06:13PM
or even

set $l7_protect 0;



set_sha1 $SHA1Cookie test;
set $COCK TechPulse_Firewall=;
set $DICK $COCK$SHA1Cookie;

if ($whiteListedIP = "true") {
set $l7_protect 1;
}

if ($request_uri ~* "lite-api.php") {
set $l7_protect 1;
}

if ($http_cookie ~ $DICK) {
set $l7_protect 1;
}


if ($l7_protect = 0) {
add_header Set-Cookie 'TechPulse_Firewall=$SHA1Cookie;Path=/';
rewrite ^ $scheme://$host$request_uri permanent;
# rewrite ^ /error-pages/checkCookie.html last;
}



ughhhhhhhhhh



Edited 1 time(s). Last edit at 05/10/2015 06:13PM by TPFreak.
Re: nginx config question, rules?
May 13, 2015 07:25AM
bum bump
Re: nginx config question, rules?
May 15, 2015 06:53AM
$10 btc to whoever can help me out lol
Re: nginx config question, rules?
May 15, 2015 07:10AM
Your going about it the wrong way, first learn what map does, try a few simple map's, get/install curl, run curl on your map test setup and see what comes back. Once you see the power of map, what curl gives you back (or not) we can try to figure out what you want is possible and maybe how. Keep config as small as possible.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: nginx config question, rules?
May 15, 2015 03:14PM
itpp2012 Wrote:
-------------------------------------------------------
> Your going about it the wrong way, first learn what map does, try a
> few simple map's, get/install curl, run curl on your map test setup
> and see what comes back. Once you see the power of map, what curl
> gives you back (or not) we can try to figure out what you want is
> possible and maybe how. Keep config as small as possible.


I've read the documentation and I do not understand how I can get it to work with a variable, can you not provide me a example that I can use instead if you know it your self ??
Re: nginx config question, rules?
May 15, 2015 03:26PM
not a single documentation on how to use it with cookies & variables, so it can't be that easy? lol
Re: nginx config question, rules?
May 15, 2015 03:44PM
set_sha1 $helpme hello;

map $http_cookie $logged_in {
default 0;
~MyCustom_Cookie $helpme;
}
if ($logged_in = $helpme) {
return 503;
}



omg heeeeeeeeeelp.. headcache -.-
Re: nginx config question, rules?
May 15, 2015 03:47PM
TPFreak Wrote:
-------------------------------------------------------
> not a single documentation on how to use it with cookies & variables,
> so it can't be that easy? lol

Thats why I said test map block with curl,

map $http_cookie $checkCookie {
default 0;
~$SHA1 $var;
}

Should work with $var but untested, else you might have to switch to Lua where complex variable handling is 'easier'.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: nginx config question, rules?
May 15, 2015 04:56PM
itpp2012 Wrote:
-------------------------------------------------------
> TPFreak Wrote:
> -------------------------------------------------------
> > not a single documentation on how to use it with cookies &
> variables,
> > so it can't be that easy? lol
>
> Thats why I said test map block with curl,
>
> map $http_cookie $checkCookie {
> default 0;
> ~$SHA1 $var;
> }
>
> Should work with $var but untested, else you might have to switch to
> Lua where complex variable handling is 'easier'.


What is $var?

What is SHA1?

Is it the full cookie encrypted?

What's the value of the cookie, and whats the name?

I only want the value encrypted. Lua is not a option for me, i can not install modules like that.
Re: nginx config question, rules?
May 18, 2015 02:29PM
bump
Re: nginx config question, rules?
May 23, 2015 08:33AM
bump
Re: nginx config question, rules?
May 25, 2015 03:26PM
bump please :( bitocin donation pl0x
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 220
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready