Sometimes it is useful to give out htpassword protected access to
certain areas of your web server (say if you are developing an app for
someone and want to give them a preview). Here is a simple way to do it:
- Log into your router – forward port 61233 (or whatever) through to your local Apache webserver
- Jump
into your Apache config file (# vi /usr/local/apache2/conf/httpd.conf)
find the “Listen” directive. Make a new line under the existing “Listen
80” and type “Listen 61233” – this will tell apache to listen on both
the normal port 80 and your new port 61233 - Somewhere else in the conf file (usualy after any other <VirtualHost> directives) put the following:
<VirtualHost 192.168.0.123:61233>
ServerAdmin my@email.address.com
DocumentRoot /path/to/directory/to/expose
ServerName myname
<Directory "/path/to/directory/to/expose">
AllowOverride All
</Directory>
</VirtualHost> - Now when someone accesses your apache server on port 61233 (eg:
http://192.168.0.123:61233) they will be shown the content within the
path you specified, next step is to password protect this content so
that not everybody can see it. - Create a file in the path you exposed called .htaccess and put the following content in it:
AuthName "SiteDemo"
AuthUserFile /path/to/directory/to/expose/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 192.168.0.0/255.255.0.0
Satisfy Any - Then creata the .htpasswd file:
# htpasswd -c /path/to/directory/to/expose/.htpasswd Bob
- Restart Apache
# /usr/local/apache2/bin/apachectl restart
- And
your all done. If you visit your site localy at
http://192.168.0.123:61233 you will not require a password, but if
anybody else visits it from the outside world they will be required to
enter the password you configured in the .htpasswd file.