Skip to content

Instantly share code, notes, and snippets.

@b0o
Last active April 8, 2020 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b0o/0c6f6555800f9fd82c7cea4b7fe4efb7 to your computer and use it in GitHub Desktop.
Save b0o/0c6f6555800f9fd82c7cea4b7fe4efb7 to your computer and use it in GitHub Desktop.
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