Skip to content

Instantly share code, notes, and snippets.

@romandobra
Created November 22, 2024 09:09
Show Gist options
  • Save romandobra/79c7bfd99590395db1a5a1d4f070a66d to your computer and use it in GitHub Desktop.
Save romandobra/79c7bfd99590395db1a5a1d4f070a66d to your computer and use it in GitHub Desktop.
nginx_cookie_auth.conf
location / {
if (!-f /var/www/auth_cookies/$cookie_AUTH_COOKIE) {
add_header Content-Type text/html;
return 200 '<form><input name="auth_cookie"><button type="submit">AUTH</button></form><script>
const f=new Proxy(new URLSearchParams(window.location.search),{get:(searchParams,prop)=>searchParams.get(prop),});
if (!f.auth_cookie == ""){document.cookie="AUTH_COOKIE="+f.auth_cookie+"; Expires=Thu, 01 Jan 2070 00:00:01 GMT";
window.location.replace("$scheme://$server_name/")};
</script>';
}
try_files $uri $uri/ =404;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment