基于虚拟目录和用户控制的web网站

基于虚拟目录和用户控制的web网站
搭建一个基于https://www.zuoye.com:22222访问的web网站,网站首页在/www/https/,内容为zuoye,可以根据https://www.zuoye.com:22222/mimi访问到的信息为mimi,该网站的实际内容在/www/secret,该网站的内容只有用户xiaoming能够查看。

首先在虚拟机中安装https服务

[root@localhost ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# yum install mod_ssl -y

然后创建对应目录,并定义网页内容

[root@localhost ~]# mkdir /www/https -v
mkdir: created directory '/www/https'
[root@localhost ~]# echo zuoye > /www/https/index.html
[root@localhost ~]# cat /www/https/index.html
zuoye
[root@localhost ~]# mkdir /www/secret -v
mkdir: created directory '/www/secret'
[root@localhost ~]# echo mimi >/www/secret/index.html
[root@localhost ~]# cat /www/secret/index.html
mimi

接下来定义配置文件/etc/httpd/conf.d/https.conf

[root@localhost ~]# vim /etc/httpd/conf.d/https.conf
listen 22222
<VirtualHost 192.168.136.140:22222>
    DocumentRoot /www/https
    ServerName www.zuoye.com
    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/https.crt
    SSLCertificateKeyFile /etc/pki/tls/certs/https.key
    alias /mimi /www/secret
</VirtualHost>
    
<Directory /www/https>
    AllowOverride None
    Require all granted
</Directory>

<Directory /www/secret>
    authtype basic
    authname "please login:"
    authuserfile /etc/httpd/users
    AllowOverride None
    Require user xiaoming
</Directory>

创建用户和密码(多创建一个xiaohong用户方便测试)

[root@localhost ~]# htpasswd -c /etc/httpd/users xiaoming
New password:
Re-type new password:
Adding password for user xiaoming
[root@localhost ~]# htpasswd  /etc/httpd/users xiaohong
New password:
Re-type new password:
Adding password for user xiaohong

然后去生成密钥和证书(redhat8)

[root@localhost conf.d]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl genrsa -aes128 2048 > https.key
[root@localhost certs]# ls
ca-bundle.crt  ca-bundle.trust.crt  https.key
[root@localhost certs]# openssl req -utf8 -new -key https.key -x509 -days 365 -out https.crt -set_serial 0
Enter pass phrase for https.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:86
State or Province Name (full name) []:sc
Locality Name (eg, city) [Default City]:cd
Organization Name (eg, company) [Default Company Ltd]:openlab
Organizational Unit Name (eg, section) []:ce
Common Name (eg, your name or your server's hostname) []:www.zuoye.com
Email Address []:admin@admin
[root@localhost certs]# ls
ca-bundle.crt  ca-bundle.trust.crt  https.crt  https.key

分别在虚拟机和Windows主机上添加域名

[root@localhost ~]# vim /etc/hosts
192.168.136.140 www.zuoye.com
C:\Windows\System32\drivers\etc\hosts
192.168.136.140 www.zuoye.com 

关闭selinux和防火墙,重启httpd服务

[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl restart httpd
Enter TLS private key passphrase for www.zuoye.com:443 (RSA) : ****

最后测试

[root@localhost ~]# curl https://192.168.136.140:22222 -k
zuoye
[root@localhost ~]# curl https://www.zuoye.com:22222 -k
zuoye

在这里插入图片描述
在这里插入图片描述

xiaohong用户无法访问
在这里插入图片描述

xiaoming用户成功访问
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值