We do the Apache user authentication according to Discuz forum www.test.com/abc/
Only you can see, but also want to show the page, this time we need to do a user authentication, that is, when you enter the user name and password, you can access.
Suppose we create an ABC directory now
[Email protected] www]# mkdir ABC
[[Email protected] www]# CD ABC
[[email protected] abc]# ls
[Email protected] abc]# cp/etc/passwd/12.tx We copy this file called 12.txt, is accessible to the file in WEB:192.168.140.100/ABC/12. TXT Well, we don't want anyone to see it. We will do a user authentication, this how to do it, let us change the configuration file:
[Email protected] abc]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf
We found in the virtual host configuration file:
<virtualhost *:80>
DocumentRoot "/data/www/"
ServerName www.test.com
Serveralias www.aaa.com
# errorlog "Logs/dummy-host2.example.com-error_log"
# customlog "Logs/dummy-host2.example.com-access_log" common
</VirtualHost>
Add these to </VirtualHost>:
<Directory/data/www/abc>
AllowOverride authconfig
AuthName "AAA"
AuthType Basic
authuserfile/data/.htpasswd
Require Valid-user
</Directory>
AUTHUSERFILE/DATA/.HTPASSWD This is where the user name and password are stored, we need to go to create it, specifically create the command:
Let's do a path first.
[Email protected] abc]# vim/etc/profile.d/path.sh
Export path= $PATH:/usr/local/mysql/bin:/usr/local/apache2/bin
[Email protected] abc]# source/etc/profile.d/path.sh
[Email protected] abc]# htpasswd-c/data/.htpasswd user1
New Password:
Re-type New Password:
Adding Password for user user1
Create/DATA/.HTPASSWD User User1
[Email protected] abc]# CAT/DATA/.HTPASSWD
User1: $apr 1$hg2g3xkl$ia. y0twloxbs6lsvbaa901
User1 followed by an encrypted password
Then create a new user without the-C, otherwise it will overwrite the
[Email protected] abc]# htpasswd/data/.htpasswd user2
New Password:
[Email protected] abc]# CAT/DATA/.HTPASSWD
User1: $apr 1$hg2g3xkl$ia. y0twloxbs6lsvbaa901
User2: $apr 1$6auov0al$d.samep6kygwp62bzc5ya1
[[email protected] abc]# apachectl-t view configuration OK
Syntax OK
[[email protected] abc]# apachectl Restart no problem restart, reload without rebooting, graceful just recall the configuration file
Let's go back to the Web refresh Www.aaa.com/abc/12.txt
This article is from the "Dream On the Ridge" blog, be sure to keep this source http://mengjunlinux.blog.51cto.com/10772888/1728974
Apache user authentication