Apache 用戶認證

   咱們根據discuz論壇來作Apache的用戶認證 www.test.com/abc/ mysql

只有本身能看到,還想再網頁上去展現,這個時候咱們須要作一個用戶認證,也就是說當你輸入用戶名和密碼以後,你纔可以訪問。 linux

   假如咱們如今建立一個abc目錄web

[root@zhangmengjunlinux www]# mkdir abcsql

[root@zhangmengjunlinux www]# cd abcapache

[root@zhangmengjunlinux abc]# lsvim

[root@zhangmengjunlinux abc]# cp /etc/passwd ./12.tx咱們把這個文件拷貝過來叫作12.txt,是能夠訪問到文件的在WEB:192.168.140.100/abc/12.txt那咱們不想讓別人看到就要作一個用戶認證,這點怎麼才能作到呢,咱們來更改一下配置文件:ide

[root@zhangmengjunlinux abc]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf ui

   咱們在虛擬主機配置文件裏找到:加密

<VirtualHost *:80>spa

    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>

在</VirtualHost>上面加入這些:

<Directory /data/www/abc>

       AllowOverride AuthConfig

       AuthName "aaa"

       AuthType Basic

       AuthUserFile /data/.htpasswd

       require valid-user

</Directory>

AuthUserFile /data/.htpasswd這是存放用戶名和密碼的地方,咱們須要去建立它,具體建立的命令:

咱們先來作一個PATH

[root@zhangmengjunlinux abc]# vim /etc/profile.d/path.sh

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache2/bin

[root@zhangmengjunlinux abc]# source /etc/profile.d/path.sh

[root@zhangmengjunlinux abc]# htpasswd -c /data/.htpasswd user1 

New password: 

Re-type new password: 

Adding password for user user1

建立/data/.htpasswd 用戶user1

[root@zhangmengjunlinux abc]# cat /data/.htpasswd

user1:$apr1$HG2G3xkL$ia.Y0twLoXBs6LSVbaa901

user1後面是加密的密碼

再建立一個新的用戶後面不加-c,否則會覆蓋掉的

[root@zhangmengjunlinux abc]# htpasswd  /data/.htpasswd user2

New password:

[root@zhangmengjunlinux abc]# cat /data/.htpasswd

user1:$apr1$HG2G3xkL$ia.Y0twLoXBs6LSVbaa901

user2:$apr1$6AUov0al$D.SAMep6KYgwP62bZC5ya1

[root@zhangmengjunlinux abc]# apachectl -t查看配置OK嗎

Syntax OK

[root@zhangmengjunlinux abc]# apachectl restart沒有問題restart一下,從新加載不用重啓,graceful只是從新調用了配置文件

咱們再去web刷新www.aaa.com/abc/12.txt

相關文章
相關標籤/搜索