Last active
April 8, 2020 13:06
-
-
Save b0o/0c6f6555800f9fd82c7cea4b7fe4efb7 to your computer and use it in GitHub Desktop.
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
server { | |
listen 8000; | |
# user to redirect to if none is passed in the URL | |
# set to the empty string ("") to disable | |
set $default_user maddy; | |
# Private user directories, e.g. localhost:8000/~user/private/secrets.txt | |
location ~ ^/~(.+?)/private(/.*)?$ { | |
auth_basic "Private directory for ~$1"; | |
auth_basic_user_file /home/$1/www/public_html/private/.htpasswd; | |
alias /home/$1/www/public_html/private$2; | |
index index.html index.htm; | |
autoindex on; | |
} | |
# Prevent access to .htpasswd files | |
location ~ ^/~(.+?)/private/.htpasswd$ { | |
return 404; | |
} | |
# User directories, e.g. localhost:8000/~user/ | |
location ~ ^/~(.+?)(/.*)?$ { | |
alias /home/$1/www/public_html$2; | |
index index.html index.htm; | |
autoindex on; | |
} | |
location ~ ^(/(index.html?)?)?$ { | |
if ($default_user) { | |
return 303 /~$default_user; | |
} | |
return 404; | |
} | |
} | |
# vim: set ft=nginx: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment