CentOS 6
Sponsored Link

Basic Authentication2014/08/25

 
Enable Basic Authentication to limit access on specific web pages.
[1] For example, set Basic Auth under the [/var/www/html/auth-basic] directory.
[root@www ~]#
vi /etc/httpd/conf.d/auth_basic.conf
# create new

<Directory /var/www/html/auth-basic>
    AuthType Basic
    AuthName "Basic Authentication"
    AuthUserFile /etc/httpd/conf/.htpasswd
    require valid-user
</Directory>
# add a user (create a new file with "-c" ⇒ only add "-c" at the first time. Do not add it 2nd time to add users)

[root@www ~]#
htpasswd -c /etc/httpd/conf/.htpasswd cent

New password:    
# set password

Re-type new password:
Adding password for user cent
[root@www ~]#
mkdir /var/www/html/auth-basic

[root@www ~]#
vi /var/www/html/auth-basic/index.html
# create a test page

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for Basic Auth
</div>
</body>
</html>

[root@www ~]#
/etc/rc.d/init.d/httpd restart

Stopping httpd:     [  OK  ]
Starting httpd:     [  OK  ]
[2] Access to the test page with a Web browser on Client and authenticate with a user which is added with htpasswd.
[3] Just accessed.
Matched Content