LInux学习笔记 --https


HTTPS


1.配置

 

[[email protected] ~]# yum install mod_ssl crypto-utils -y

LInux学习笔记 --https


[[email protected] ~]# genkey www.westos.com   ##调用genkey,同时为生成的文件指定唯一名称

LInux学习笔记 --https

 

记录生成的证书和关联的私钥的位置

 LInux学习笔记 --https


继续使用对话框,并选择合适的**大小。(默认的2048位**为推荐值)

 LInux学习笔记 --https


在生成随机数时比较慢,敲键盘和移动鼠标可以加速

 LInux学习笔记 --https

LInux学习笔记 --https


拒绝向认证机构(CA)发送证书请求(CSR)。

 LInux学习笔记 --https


拒绝加密私钥

 LInux学习笔记 --https


为服务器提供合适的身份。Common Name必须与服务器的主机全名完全匹配。

 LInux学习笔记 --https


[[email protected] ~]# cd /etc/pki/tls/private/

[[email protected] private]# ls

localhost.key www.westos.com.key

LInux学习笔记 --https


[[email protected] ~]# mkdir /var/www/virtual/login.westos.com/html -p

[[email protected] ~]# vim /var/www/virtual/login.westos.com/html/index.html

[[email protected] ~]# cat /var/www/virtual/login.westos.com/html/index.html

 LInux学习笔记 --https

 

[[email protected] ~]# vim /etc/httpd/conf.d/login.conf

<Virtualhost>

ServerName "login.westos.com"

DocumentRoot "/var/www/virtual/login.westos.com/html"

CustomLog "logs/login.log" combined

SSLEngine on ##开启https功能

SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt ##证书

SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key ##**

</Virtualhost>


<Directory>

Require all granted ##网页重写实现自动访问https

</Directory>

 

<Virtualhost>

ServerName "login.westos.com"

RewriteEngine on

RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]

</Virtualhost>

 

## ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]

## ^(/.*)$ 客户主机在地址栏中写入的所有字符

## https:// 定向成为的访问协议

## %{HTTP_HOST} 客户请求主机

## $1 $1的值就表示^(/.*)$的值

## [redirect=301] 临时重定向 302为永久重定向

 LInux学习笔记 --https


[[email protected] ~]# systemctl restart httpd

 LInux学习笔记 --https


【浏览器所在主机】

[[email protected] ~]# vim /etc/hosts

172.25.254.129 login.westos.com

LInux学习笔记 --https


2.测试

浏览器访问 https://login.westos.com 会自动跳转到 http://login.westos.com 实现网页数据加密传输 

LInux学习笔记 --https

LInux学习笔记 --https

LInux学习笔记 --https

LInux学习笔记 --https