apache用户认证
2016-03-23 19:56
651 查看
比如在www.test.com/abc/下的文件,要在网页上展示,又只允许管理员才能够查看,
我们就可以去做一个用户认证,需要去输入用户名和密码,只有用户名和密码正确之后才能够去访问。
[root@No ~]# cd /data/www
[root@No www]# cd test/
[root@No test]# cp /etc/passwd ./1.txt
打开网页,输入www.test.com/test/1.txt是可以访问的。
假如1.txt这个文件很重要,我们要在网页上展示,只允许自己查看,我们就来做一个用户认证。
编辑虚拟主机文件:
[root@No test]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/data/www"
ServerName www.test.com
ServerAlias www.aaa.com
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
<Directory /data/www/test>
AllowOverride AuthConfig
AuthName "zhanghaomima"
AuthType Basic
AuthUserFile /data/.htpasswd #密码文件
require valid-user
</Directory>
</VirtualHost>
:wq
[root@No test]# vim /etc/profile.d/path.sh
修改为:
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache2/bin
:wq
[root@No test]# source /etc/profile.d/path.sh
这样apache也可以快速启动,不用再输入过长的命令。
生成密码文件:
[root@No test]# htpasswd -c /data/.htpasswd user1 //user1为用户名
New password: //密码为123456
Re-type new password:
Adding password for user user1
如果在添加一个新的用户,就不能使用htpasswd -c /data/.htpasswd user2了。
要把-c去掉,否则会覆盖掉之前的文件。
[root@No test]# apachectl -t
Syntax OK
[root@No test]# apachectl graceful
//重新加载。不需要重启。
然后在网页上刷新之前的页面,会看到以下提示:
箭头所指的就是我们虚拟主机里面的AuthName "zhanghaomima"
输入用户名:user1
密码:123456
就可以访问了。
我们就可以去做一个用户认证,需要去输入用户名和密码,只有用户名和密码正确之后才能够去访问。
[root@No ~]# cd /data/www
[root@No www]# cd test/
[root@No test]# cp /etc/passwd ./1.txt
打开网页,输入www.test.com/test/1.txt是可以访问的。
假如1.txt这个文件很重要,我们要在网页上展示,只允许自己查看,我们就来做一个用户认证。
编辑虚拟主机文件:
[root@No test]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/data/www"
ServerName www.test.com
ServerAlias www.aaa.com
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
<Directory /data/www/test>
AllowOverride AuthConfig
AuthName "zhanghaomima"
AuthType Basic
AuthUserFile /data/.htpasswd #密码文件
require valid-user
</Directory>
</VirtualHost>
:wq
[root@No test]# vim /etc/profile.d/path.sh
修改为:
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache2/bin
:wq
[root@No test]# source /etc/profile.d/path.sh
这样apache也可以快速启动,不用再输入过长的命令。
生成密码文件:
[root@No test]# htpasswd -c /data/.htpasswd user1 //user1为用户名
New password: //密码为123456
Re-type new password:
Adding password for user user1
如果在添加一个新的用户,就不能使用htpasswd -c /data/.htpasswd user2了。
要把-c去掉,否则会覆盖掉之前的文件。
[root@No test]# apachectl -t
Syntax OK
[root@No test]# apachectl graceful
//重新加载。不需要重启。
然后在网页上刷新之前的页面,会看到以下提示:
箭头所指的就是我们虚拟主机里面的AuthName "zhanghaomima"
输入用户名:user1
密码:123456
就可以访问了。
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍