Apache Open Directory Encryption function

Source: Internet
Author: User
Tags require password protection

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.