Wednesday 5 September 2012

configure httpd to use passwords and/or network location to restrict access to content

Install apache
#yum install httpd -y

#######################################################################
USING PASSWORDS TO RESTRICT ACCESS
#######################################################################

Edit the apache config
#vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/protected">
    AllowOverride Authconfig
</Directory>

Create the protected area

#mkdir /var/www/html/protected
#echo "Only authorised personal can see this" > /var/www/html/protected/index.html

Use htpasswd to create an auth file
#htpasswd -c -m /var/www/userfile username

Create the following file with the following config
#vim /var/www/html/protected/.htaccess

AuthName "Access to protected area"
AuthType Basic
AuthUserFile /var/www/userfile
require valid-user

Restart apache
#service httpd restart

You should then be prompted when you try and access http://servername/protected

#######################################################################
USING NETWORK LOCATION TO RESTRICT ACCESS
#######################################################################

Edit the apache config
#vim /etc/httpd/conf/httpd.conf

Directory "/var/www/html/protected">
    Order allow,deny
    Allow from .example.com
    Deny from All
</Directory>

Restart apache
#service httpd restart



No comments:

Post a Comment