Suppose Apache's root directory is/usr/local/apache/
HTPASSWD is located in the Apache Bin directory
1. Establish user
Htpasswd-c/root/.htpasswd Cnsecer
Where. htpasswd is the file that stores the account password Cnsecer is the user name
The system will require you to enter the password two times
2. Editor httpd.conf
Add the following code to the httpd.conf
<directory "/data/www/cnsecer.com/test/" >
AuthType Basic
AuthName "Authorization"
authuserfile/root/.htpasswd
Require User Cnsecer
</Directory>
where "/data/www/cnsecer.com/test/" is the directory to which permissions are accessed
AuthUserFile Deposit Account Password file
Require username immediately after user name allowed to access
3. Restart Apache
Use the. htaccess profile to set the password protection tutorial for a directory
1, use Apache Htpasswd.exe to create a password file, command see PHP Recommended tutorial: Apache HTPASSWD Command Usage detailed
2. Create a. htaccess configuration file (e.g./www/manage) in a directory that needs to be protected.
3. Write configuration information in the. htaccess configuration file,. htaccess configuration file is different from Apache configuration file, no directory
#vi. htaccess
AuthType Basic
AuthName "WORKING CENTER" #引号中的是说明文字, casually write
AUTHUSERFILE/ETC/.PASSWD #AuthUserFile指的是保存用户名和密码的文件位置 (absolute path)
Require like Likeli #用户名为like, the password is Likeli (if this line is written as Require valid-user table
Indicates that only the legitimate users included in the. htpasswd file can be accessed. ) 4, Save the. htaccess configuration file and place the. htaccess profile
In a directory where password protection is required, such as the/data/www/xxxx directory
The above. htaccess configuration function is the same as the one implemented by the first method.
When browsing the encrypted website, you need to enter the username password.
. htaccess Configuration Considerations
In addition to the problems that need to be noticed with the Apache httpd.conf configuration, one easy error is that if the configuration is not correct, it will appear. htaccess configuration file does not work because of the Apache allowoverride Directive, Determines whether your. htaccess can be opened and enabled normally. From security considerations, the AllowOverride properties of the site root in the Apache httpd.conf configuration file are generally configured to disallow No Override, that is,
<directory/>
AllowOverride None
</Directory>
So to enable Apache to properly read the contents of the. htaccess file, turn on the. htaccess function so that the settings in the. htaccess configuration file work, you must configure the site root directory or the directory where the. htaccess resides. Change allowoverride None to allowoverride all.