Nginx dev environment secure by IP or cookie

Moki Lv6

Nginx configuration:

configuration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
set_real_ip_from 10.0.0.0/8;
real_ip_header X-Real-IP;

map $cookie_letmein $authentication_cookie {
"cookie-special-value" "1";
default "0";
}

geo $authentication_ip {
1.2.3.4 "1";
2.3.4.5 "1";
3.4.5.6 "1";
123.123.123.123 "1";
default "0";
}

map $authentication_cookie$authentication_ip $authentication {
"11" "off";
"10" "off";
"01" "off";
default "Authentication required";
}

Set cookie in browser:

1
2
3
4
5
6
7
8
9
function setCookie(name, value, domain) {
var exdays = 3650;
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = encodeURI(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString() + "; path=/; domain="+domain);
document.cookie = name + "=" + c_value;
}

setCookie('letmein','cookie-special-value','.moki.dev');
On this page
Nginx dev environment secure by IP or cookie