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