Apache server configuration Web page access permissions

  
Assuming you have some sensitive information to be placed on the Intranet/Internet, you may first think of developing a user authentication system to protect your Web pages. In fact, Apache itself has a mechanism to restrict users from accessing Web pages, and it is not complicated to implement.

This article describes the implementation on Linux + Apache:

1, modify http.conf

Suppose you want to control different access to the directory under /usr/local/apache/htdocs Permissions, you can add a line between and:

AllowOverride All

means that the access permissions of different directories under /usr/local/apache/htdocs are made by the .htaccess file in that directory. To control, and the permission policies of different directories can be overwritten by each other.

2, edit the .htaccess file in the directory you want to control

Assuming your phpmyadmin directory is under /usr/local/apache/htdocs, you can create it in the phpmyadmin directory. A .htaccess file with the following contents:

AuthUserFile /usr/local/apache/pass/pwdPhp

AuthType Basic

AuthName "Database Security Zone"

ErrorDocument 401 /catchErrors/err_401.html


require valid-user


This file explains several issues:

(1) User information is stored in /usr/local/apache/pass/pwdPhp.

(2) The authentication type is basic (in addition to some other encryption types).

(3) The html file pointed to by ErrorDocument.

(4) Authentication method: user-authenticated (valid-user) or group-authenticated (valid-group).

3. Generate user Password file

There is a user password generator: htpasswd (under /usr/local/apache/bin), which can add user password information to the specified file, such as /u Sr/local/apache/pass/pwdPhp. My user password file contents are as follows:

admin:a0Hplbj33QjV2

guest:R0BYSO383QjVT

4. Restart apache deamon

/usr/local/apche/bin/apachectl restart

5. Test

Browse protected pages in IE, such as http://ip/phpmyadmin/(may need Refresh several times to work.) An authentication window should appear. You need to enter the username (admin /guest) and password (******) to access this page.

Copyright © Windows knowledge All Rights Reserved