首先搭建静态https的服务器:
①使用yum下载文件包,进行httpd文件安装
[root@localhost ~]# yum install mod_ssl -y
②配置创建连接的index.html文件(访问的目录)
[root@localhost www]# mkdir -p /www/https
[root@localhost www]# cd /www/https/(这里可能一次进不去,要一步步cd)
[root@localhost https]# vim index.html
// vim编辑index的文件
This is my first https page
③配置更改阿帕奇登录页面的权限设置
[root@localhost certs]# cd /etc/httpd/conf.d
autoindex.conf host.conf README ssl.conf userdir.conf welcome.conf
[root@localhost conf.d]# vim host.conf
//<Directory>为分配权限 (文件位置,允许人,给予权限)
<Directory "/www/https">
AllowOverride none
Require all granted
</Directory>
//监听这个ip地址下的443端口
#listen 443
// <VirtualHost>配置虚拟机(文档位置,服务名,ssl服务引擎打开,协议选择,密码选择套件,认证证书(公钥,信息),配置私钥)
<VirtualHost 192.168.220.132:443>
DocumentRoot "/www/https"
ServerName 192.168.220.132
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
#证书
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
#密钥
</VirtualHost>
[root@localhost conf.d]# systemctl stop firewalld
//刷新,关闭防火墙,设置可信任
[root@localhost conf.d]# setenforce 0
[root@localhost conf.d]# systemctl restart httpd
这个时候去访问(https://192.168.220.132显示为一个不安全的连接(原因:自己搭建的服务器没有获得AC认证))
基于https协议下搭建一个访问需要验证的网页:
//由于之前已经ym配置好centos
//首先设置密码和密码文件位置
[root@localhost usr]# htpasswd -c /usr/local/etc/passwords test
(密码建议)passwd:123456
[root@localhost usr]# mkdir -pv /usr/local/mysecret
[root@localhost usr]# echo "My secret" >> /usr/local/mysecret/index.html
//转到密码文件的index.html 并将passwords存放在mysecret下
[root@localhost usr]# cd /etc/httpd/conf.d
[root@localhost usr]# vim host.conf
//设置为监听8001端口
listen 8001
<Directory "/usr/local/mysecret">
AuthType Basic
AuthName "Hello"
AuthBasicProvider file
AuthUserFile "/usr/local/etc/passwords"
Require user test
</Directory>
<VirtualHost "192.168.220.132:8001">
alias "/mysecret" "/usr/local/mysecret"
ServerName 192.168.220.132
</VirtualHost>
//alias为一个转移符,将如果访问文件"/mysecret",则会转移到"/usr/local/mysecret"
[root@localhost conf.d]# systemctl stop firewalld
//刷新,关闭防火墙,设置可信任
[root@localhost conf.d]# setenforce 0
[root@localhost conf.d]# systemctl restart httpd
重启httpd服务然后去浏览器完工