From cb821faf54a8feb590550fb3a2ad0e4fa8372f4b Mon Sep 17 00:00:00 2001 From: kevinnls Date: Wed, 2 Sep 2026 02:37:30 +0530 Subject: [PATCH] init --- .gitignore | 1 + Justfile | 26 ++++++++++++++++++++++++++ conf.d/server.conf | 33 +++++++++++++++++++++++++++++++++ www/clear.html | 14 ++++++++++++++ www/flavour.html | 13 +++++++++++++ www/index.html | 46 ++++++++++++++++++++++++++++++++++++++++++++++ www/set.html | 14 ++++++++++++++ 7 files changed, 147 insertions(+) create mode 100644 .gitignore create mode 100644 Justfile create mode 100644 conf.d/server.conf create mode 100644 www/clear.html create mode 100644 www/flavour.html create mode 100644 www/index.html create mode 100644 www/set.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a151c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/ssl diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..0e2c55c --- /dev/null +++ b/Justfile @@ -0,0 +1,26 @@ +NAME := 'cookies' + +reload: test + podman exec --tty {{ NAME }} nginx -sreload +test: + podman exec --tty {{ NAME }} nginx -t +sh: + podman exec --tty --interactive {{ NAME }} sh +logs: + podman logs --follow {{ NAME }} + +genssl DOMAIN: + mkdir -p ssl + openssl req -x509 -new -keyout ssl/key.pem -out ssl/cert.pem -noenc -days 3 \ + -addext 'subjectAltName=DNS:*.{{ DOMAIN }},DNS:{{DOMAIN}}' \ + -subj '/CN={{ DOMAIN }}' + +container: + podman run \ + --detach --tty --rm --replace \ + --name cookies \ + --publish 8443:443 \ + --volume ./conf.d:/etc/nginx/conf.d:ro,z \ + --volume ./www:/srv/www:ro,z \ + --volume ./ssl:/etc/nginx/ssl:ro,z \ + nginx:alpine diff --git a/conf.d/server.conf b/conf.d/server.conf new file mode 100644 index 0000000..9101ed8 --- /dev/null +++ b/conf.d/server.conf @@ -0,0 +1,33 @@ +map $host $flavour { + default 'butter'; + a.website.com 'chocochip'; + b.website.com 'peanutbutter'; +} +server { + listen 443 ssl; + ssl_certificate /etc/nginx/ssl/cert.pem; + ssl_certificate_key /etc/nginx/ssl/key.pem; + server_name a.website.com b.website.com sub.a.website.com; + + root /srv/www; + + try_files $uri $uri.html /index.html =200; + + add_header 'access-control-allow-origin' '$http_origin'; + add_header 'access-control-allow-credentials' 'true'; + + sub_filter '%COOKIE%' '$cookie_flavour'; + + location /flavourtest { + return 200 '$host and $flavour\n'; + } + location /set { + try_files $uri $uri.html /index.html =200; + add_header set-cookie 'flavour=$flavour; max-age=3600;'; + } + location /clear { + try_files $uri $uri.html /index.html =200; + add_header set-cookie 'flavour=$flavour; max-age=0'; + } + error_page 497 https://$host:$request_port$request_uri; +} diff --git a/www/clear.html b/www/clear.html new file mode 100644 index 0000000..166cfb0 --- /dev/null +++ b/www/clear.html @@ -0,0 +1,14 @@ + + + + + clear! + + + + +

+ cleared cookie data. redirecting to / in a bit +

+ + diff --git a/www/flavour.html b/www/flavour.html new file mode 100644 index 0000000..da87f45 --- /dev/null +++ b/www/flavour.html @@ -0,0 +1,13 @@ + + + + + hello! + + + +

+ Here is the cookie flavour: %COOKIE% +

+ + diff --git a/www/index.html b/www/index.html new file mode 100644 index 0000000..106ddaf --- /dev/null +++ b/www/index.html @@ -0,0 +1,46 @@ + + + + + hello! + + + + +
+
+ Here is the cookie flavour: %COOKIE% +
+
+ +
+ +
+
the cookie when i request…
+ a.website.com + + + b.website.com + + + sub.a.website.com + +
+ + diff --git a/www/set.html b/www/set.html new file mode 100644 index 0000000..0e2f173 --- /dev/null +++ b/www/set.html @@ -0,0 +1,14 @@ + + + + + clear! + + + + +

+ setting flavour to %COOKIE% and redirecting to / +

+ +