LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 11-22-2013, 05:35 PM   #1
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 658

Rep: Reputation: 35
Question [Nginx] Recommended way to secure a directory?


Hello

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 a few articles, but still have a few questions for the experts:
  1. Which file should I edit? It looks like /etc/nginx/sites-available/default is included in /etc/nginx/nginx.conf
  2. For location, what do "~" and "^~" mean? Are they shorthands for /usr/share/nginx/www/?
  3. 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?
  4. Who should own the htpasswd file (root? www-data?), and with which access rights (600)?

Thank you.
 
Old 11-25-2013, 09:27 PM   #2
baldur_1
Member
 
Registered: Sep 2010
Posts: 275

Rep: Reputation: 28
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.
 
Old 11-26-2013, 05:51 AM   #3
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 658

Original Poster
Rep: Reputation: 35
Thanks for the help.

After more reading and experimenting, I got it to work:
  1. Generate a password through eg. http://www.askapache.com/online-tool...swd-generator/. The Digest algorithm doesn't seem supported by Nginx, so I chose the MD5 format
  2. 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
  3. 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
  4. Create the actual directory in the docroot: mkdir /usr/share/nginx/www/mysecret ; chown www-data:www-data /usr/share/nginx/www/mysecret
  5. 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?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create inconvertible expire time in secure link in nginx IIRezaII Linux - Server 0 06-26-2013 03:44 AM
nginx + php-fpm and nginx modules fantasygoat Linux - Server 0 06-09-2011 12:21 PM
Nginx experts help me-problem when using Nginx php-fpm !!! HuMan-BiEnG Linux - Server 2 04-17-2011 02:30 PM
NGINX with PHP-FPM vis NGINX with Spawn-FCGI WhisperiN Linux - Server 1 03-15-2011 06:39 PM
recommended directory structure for application system development mherboly Linux - General 4 04-29-2010 04:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration