HTTP: Configure private directories.

Share this link

Install the “Web server” package group:

# yum groupinstall -y "Web server"

There are several ways to restrict access to directories:

1) host-based private directories
To only allow test.example.com (add the name/IP address in the /etc/hosts file if necessary) to access a specific directory (here private), edit the /etc/httpd/conf/httpd.conf file and type:

<Directory "/var/www/html/private">
AllowOverride None
Options None
Order allow,deny
Allow from test.example.com
</Directory>

Check the configuration file:

# service httpd configtest

Create the private directory:

# mkdir -p /var/www/html/private
# restorecon -R /var/www/html/private

2) user-based private directories
To only allow me to access a specific directory (here private), edit the /etc/httpd/conf/httpd.conf file and type:

<Directory "/var/www/html/private">
AuthType Basic
AuthName "Password protected area"
AuthUserFile /etc/httpd/conf/passwd
Require user me
</Directory>

Check the configuration file:

# service httpd configtest

Create the private directory:

# mkdir -p /var/www/html/private
# restorecon -R /var/www/html/private

Create the passwd file and store me’s password:

# htpasswd -c /etc/httpd/conf/passwd me

Note: the .htpasswd file can locally be used instead of the httpd.conf file in 1) and 2) for the same purpose.

Whatever the option chosen, add a new rule to the firewall:

# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

Save the firewall configuration:

# service iptables save

Activate the httpd service at boot:

# chkconfig httpd on

Start the httpd service:

# service httpd start

Check the httpd service:

# yum install -y elinks
# elinks http://localhost/private
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
2 comments on “HTTP: Configure private directories.
  1. Santosh Lohar says:

    Hi CertDepot, Thanks for you valuable post which made way understanding . Thanks for your effort. I have some queries on directory level access on web server section.
    I have followed all the steps from this post but still I am getting error ” The requested URL /private not found on this server ” I am posting my configuration details .
    vi /etc/hosts

    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
    10.8.8.70 ipa.rhce.local ipa
    192.168.43.81 station81.example.com station81
    192.168.43.81 station101.example.com station101
    192.168.43.81 station102.example.com station102
    192.168.43.82 test.example.com test

    ###################
    cat /etc/httpd/conf/httpd.conf

    ########## from createdepot – directory access #######3

    AllowOverride None
    Options None
    Order allow,deny
    Allow from test.example.com

    AuthType Basic
    AuthName “Password protected area”
    AuthUserFile /etc/httpd/conf/passwd
    Require user me

    ############
    Can you please check what went wrong .

    • Sam says:

      Hmm Which OS are you using? This is for Centos 6.x.
      Check your log files including the apache, website and the messages files at /var/log/. That should point you in the correct direction!

      If you are studying for RHCE I would recommend setting up a local DNS, there may be an issue with the setup. Try the text browser lynx for different features!

Leave a Reply

Upcoming Events (Local Time)

There are no events.

RHCSA7: Task of the day

Allowed time: 10 minutes.
Create an EXT4 file system mounted by UUID in /etc/fstab under /vol based on a logical volume of 28 logical extents.

RHCE7: Task of the day

Allowed time: 3 minutes.
Configure your machine to be a router.

Follow me on Twitter

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...