- 添加账号abc
[root@localhost conf.d]# htpasswd -c /etc/httpd/zhanghao abc
New password:
Re-type new password:
Adding password for user abc
- 添加账号tom
[root@localhost conf.d]# htpasswd /etc/httpd/zhanghao tom
New password:
Re-type new password:
Adding password for user tom
查看账号
- 创建
/usr/local/mysecret/
目录
[root@localhost conf.d]# mkdir /usr/local/mysecret
- 写内容放入文件
[root@localhost conf.d]# echo "This is mysecret!" > /usr/local/mysecret/index.html
- 配置vhost.conf文件
<directory /usr/local/mysecret>
authtype basic
authname "请输入密码:"
authuserfile /etc/httpd/zhanghao
require user abc tom
</directory>
<virtualhost 192.168.209.140:80>
documentroot /www/hehe
alias /hehe /usr/local/mysecret
servername www.hehe.com
</virtualhost>
- 创建目录并写入内容
[root@localhost conf.d]# mkdir /www/hehe
[root@localhost conf.d]# echo welcome to hehe > /www/hehe/index.html
- 重启httpd服务
[root@localhost conf.d]# systemctl restart httpd
- 在本地解析文件中添加www.hehe.com。路径
C:\Windows\System32\drivers\etc
下的hosts文件。
- 测试