Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need to set up a web server at home, and Nginx looks like a good solution to deliver static contents as well as run Python apps through WSGI.
I also need to secure a directory whose access should prompt the user for a password.
I read afewarticles, but still have a few questions for the experts:
Which file should I edit? It looks like /etc/nginx/sites-available/default is included in /etc/nginx/nginx.conf
For location, what do "~" and "^~" mean? Are they shorthands for /usr/share/nginx/www/?
Should I put the htpasswd file outside the www doc directory (eg. /usr/share/nginx/www/), in the Nginx configuration directory (/etc/nginx/), or yet elsewhere?
Who should own the htpasswd file (root? www-data?), and with which access rights (600)?
i dont have a ton of experience with nginx but i do have quite a bit with websites and hosting and i know i can answer a couple of these questions. the htpasswd file should not be in the directory of the website at all. that can lead to security issues. what should be done is it should be encoded into the website configuration file. this is the most secure way of using htpasswd files.
if you do put it as a file on the website then it needs to be in the directory for which it is being referenced so for every directory where you want a password prompt, you should have a htpasswd file and if you do that then it should be owned by root to prevent changes to the file. that is really not an advisable method though.
Create a file to hold this information. For added protection, it should reside outside the web docroot, eg. /etc/nginx/.passwd, and paste the login/password line
As child processes spawned by Nginx run as www-data, secure this file thusly: chown www-data:www-data /etc/nginx/.passwd ; chmod 640 /etc/nginx/.passwd
Create the actual directory in the docroot: mkdir /usr/share/nginx/www/mysecret ; chown www-data:www-data /usr/share/nginx/www/mysecret
As, by default, directory listing is not allowed, create an index.html file in the directory, connect from a remote browser, and check that you are indeed prompted for a login/password. Logs are available in /var/log/nginx/.
There's just one last thing, which I assume is browser-related: After successfully connecting to the web page, the browser no longer prompts the user for a login/password, even after emptying the cache. Tried Chrome and Firefox, same result. Does someone know how to tell the browser to entirely forget about the whole thing, and start afresh?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.