LAMP环境搭建完成,Discuz搭建完成,如何实现用户认证访问Discuz论坛中特定的文件?
Apache的用户认证
1、准备加密文件,无需认证即可查看重要文件
[root@daixuan abc]# cd /data/www/abc
[root@daixuan abc]# cp /etc/passwd ./12.txt
在浏览器中访问:http://www.test.com/abc/12.txt
2、修改Apache的虚拟主机配置文件,实现特定目录下文件用户认证访问
[root@daixuan abc]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 红色为添加内容
<VirtualHost *:80>
# ServerAdmin [email protected]
DocumentRoot "/data/www"
ServerName www.test.com
ServerAlias www.daixuan.com
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
<Directory /data/www/abc/> 加密目录
AllowOverride AuthConfig
AuthName "Please input your name and password"
AuthType Basic
AuthUserFile /data/.htpasswd 存放验证用户名和密码的文件
require valid-user 提示输入认证
</Directory>
</VirtualHost>
3、添加验证用户user1
插曲:添加htpasswd的绝对路径到/etc/profile.d/path.sh
[root@daixuan abc]# vim /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache2/bin
[root@daixuan abc]# source /etc/profile.d/path.sh
[root@daixuan abc]# htpasswd -c /data/.htpasswd usr1 -c create创建.htpasswd文件,添加user1
New password:
Re-type new password:
Adding password for user usr1
[root@daixuan abc]# cat /data/.htpasswd
usr1:$apr1$oNwu8OJg$7U62ZQBEQ9m67eB7FKjMs0
[root@daixuan abc]# htpasswd /data/.htpasswd user2 添加user2,不加-c,否则覆盖文件
New password:
Re-type new password:
htpasswd: password verification error
[root@daixuan abc]# apachectl -t
Syntax OK
[root@daixuan abc]# apachectl graceful