LInux学习笔记 --https


HTTPS


1.配置

 

[root@localhost ~]# yum install mod_ssl crypto-utils -y



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

 

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

 


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

 


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

 



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

 


拒绝加密私钥

 


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

 


[root@localhost ~]# cd /etc/pki/tls/private/

[root@localhost private]# ls

localhost.key www.westos.com.key



[root@localhost ~]# mkdir /var/www/virtual/login.westos.com/html -p

[root@localhost ~]# vim /var/www/virtual/login.westos.com/html/index.html

[root@localhost ~]# cat /var/www/virtual/login.westos.com/html/index.html

 

 

[root@localhost ~]# 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为永久重定向

 


[root@localhost ~]# systemctl restart httpd

 


【浏览器所在主机】

[root@foundation66 ~]# vim /etc/hosts

172.25.254.129 login.westos.com



2.测试

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





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值