protecting your apache virtual host howto

if you need to have apache web server protect a specific virtual host (website) you need four simple steps.

  1. Create .htpassword file in a root protected path and add the first user
    su -
    mkdir /var/www/htpassword/
    htpass -cm /var/www/htpassword/.htpassword admin
  2. add more users to .htpassword file
    htpass -m /var/www/htpassword/.htpassword username
  3. add .htaccess to your host public directory (or document root), it will look similar to this
    AuthName "Restricted Area"
    AuthType Basic
    AuthUserFile /var/www/htpass/.htpasswd
    AuthGroupFile /dev/null
    require valid-user

    this is simple and obvious, but in case of ruby on rails you need to add it to your public directory not rails project root directory.

now, you need to restart your apache websrever to update to latest configuration, then point your browser to your website and check it’s working, it should prompt you for username and password.

have a nice sys admin!

howto, linux, PHP, Ruby and Ruby On Rails, System Administration, troubleshooting , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>