Created
May 14, 2019 12:20
-
-
Save vtr0n/0eb128cd556261d953c9f63007b6a76b to your computer and use it in GitHub Desktop.
nginx http auth with cookies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create the password file for user 'admin' | |
sudo htpasswd -c /etc/nginx/.htpasswd admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Admin Panel | |
location /Admin/ { | |
set $auth_basic "closed site"; | |
if ($cookie_adminCookie = "secretCookieValue") { | |
set $auth_basic off; | |
} | |
auth_basic $auth_basic; | |
auth_basic_user_file /etc/nginx/.htpasswd; | |
error_page 404 = @admin; | |
} | |
location @admin { | |
root /var/www; | |
# you can use rewrite here, for example: | |
# rewrite ^/Admin/(.*)$ /public/index.php?Admin/$1 break; | |
# set php fascgi params: | |
# fastcgi_pass unix:/run/php/php7.2-fpm.sock; | |
# include fastcgi_params; | |
# fastcgi_param SCRIPT_FILENAME $request_filename; | |
# set cookie life for 1 year | |
add_header Set-Cookie "adminCookie=secretCookieValue;max-age=3153600000;path=/" always; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment