weewee 发表于 2015-7-13 09:09:39

apache用户认证

                      先创建一个“用户认证”目录(设为abc)
# cd /data/www
# mkdir abc
进入abc目录
# cd abc
拷贝一个文件(作用:验证配置是否生效)
# cp /etc/passwd 12.txt
没编辑“虚拟主机配置文件”之前,可直接打开12.txt的内容,
不安全


编辑“虚拟主机配置文件”
# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
在Discuz主机配置里添加:
<Directory /data/www/abc/>
    AllowOverride AuthConfig
    AuthName "yonghuming"
    AuthType Basic
    AuthUserFile /data/.htpasswd
    require valid-user
</Directory>
配置完成,需创建“身份验证用户user1”
# /usr/local/apache2/bin/htpasswd -c /data/.htpasswd user1
New password:******
Re-type new password:******
Adding password for user user1
# apachectl -t
Syntax OK
# apachectl graceful
在浏览器输入www.lam.com/abc/12.txt

这样就有安全性了。

自学:find / -name htpasswd -type f          ##查找htpasswd的绝对路径
                   

页: [1]
查看完整版本: apache用户认证