Ever wondered how you can password protect a folder and the underlying content with nginx the same way Apache does? Pretty simple.
First create a htpass-file like so:
1 |
htpasswd -bc htpass NewUser NewPassword |
Edit your site’s configuration file by adding the following lines of code inside the server-block:
1 2 3 4 |
location ^~ /secret { auth_basic "Restricted"; auth_basic_user_file /etc/nginx/htpass; } |
And your folder should be password protected. :)
For those, like me, who need to password protect a PHP folders here is what i used:
http://www.rosehosting.com/blog/password-protecting-directories-with-nginx/