Access Protection with Apache. htaccess

Source: Internet
Author: User
Tags auth

Under Apache server, you can control access to a single directory, such as IP filtering, requiring a user name password for basic auth, and so on. The following uses the. htaccess to implement the Auth.

First in the configuration file http.conf, to the directory you want to control, turn on the override function, if it is set to allowoverride none, the. htaccess file will not work.

" /your/site/dir/need/to/control/ ">    Options followsymlinks multiviews    multiviewsmatch any    allowoverride all    Require All granted</Directory>

The above allowoverride can be selected FileInfo, Authconfig, Limit, all, none.

After the configuration file is saved, restart the server. I'm doing it under Mac OS X Yosemite

sudo apachectl restart

Apache configuration file to complete this, now create the. htaccess file in the corresponding site directory, as in the above/your/site/dir/need/to/control/.htaccess, the following

' name '  /your/site/dir/need/to/control/. Htpasswdauthtype basicrequire valid-user

The above name is the user name when the user login, AuthUserFile is the file that holds password. Here's how to build the. htpasswd file:

Use the HTPASSWD command to generate the. htpasswd file under Console (Mac OS X Yosemite)

htpasswd-bc/your/site/dir/need/to/control/.htpasswd name password

Now in the browser access http://host/your/.../control/, will pop up the dialog box, enter the name, password can.

Access Protection with Apache. htaccess

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.