Linux 的Apache服务之https与网页重写

https

1.https概述:

HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket
Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。它是一个URI scheme(抽象标识符体系),句法类同http:体系。用于安全的HTTP数据传输。https:URL表明它使用了HTTP,但HTTPS存在不同于HTTP的默认端口及一个加密/身份验证层(在HTTP与TCP之间)。这个系统的最初研发由网景公司(Netscape)进行,并内置于其浏览器Netscape
Navigator中,提供了身份验证与加密通讯方法。现在它被广泛用于万维网上安全敏感的通讯,例如交易支付方面。

2.配置 HTTPS

yum install -y httpd mod_ssl        ##安装Apache服务及mod_ssl密钥生成模块
systemctl reload httpd              ##重新加载Apache服务
yum install -y crypto-utils.x86_64  ##安装crypto-utils加密工具
genkey www.westos.com               ##生成密钥
Next >> 1024 >> Next >> No >> Next >>
##填写密钥信息
>> CN
>> shannxi
>> xi'an
>> westos
>> linux
>> www.westos.com

vim /etc/httpd/conf.d/ssl.conf
100 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
107 SSLCertificateKeyFile   /etc/pki/tls/certs/www.westos.com.key

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

这里写图片描述

3.测试服务

完成后重载apache服务,

echo`hostname`>/var/www/html/index.html     ##写入测试文件

打开firefox,地址栏输入https://localhost
如果访问到刚写入的内容并且有加密协议(地址栏前面有个锁)说明配置生效
这里写图片描述

  • 它写的是我的证书不被信任,当然了,我的证书又没被认证。(点I Understand the Risks)

这里写图片描述

  • 再点Add Exception

这里写图片描述

这里写图片描述
直接输入localhost访问的页面是未加密的,如下图
这里写图片描述

https网页重写

  • 把所有 80 端口的请求全部重定向由 https 来处理
vim /var/www/westos/login/html/login.conf
<Virtualhost *:443>
        ServerName login.westos.com
        DocumentRoot /var/www/westos/login/html
        CustomLog "logs/login.log" combined
    SSLEngine on            开启https功能
    SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
    证书
    SSLCertificateKeyFile   /etc/pki/tls/certs/www.westos.com.key
    密钥
</Virtualhost>

<Directory "/var/www/westos/login/html">
        Require all granted
</Directory>

<Virtualhost *:80>
    ServerName login.westos.com
    RewriteEngine on        开启网页重写功能
    RewriteRule ^(/.*)$ https://${HTTP_HOST}$1 [redirect=301]
</Virtualhost>
^(/.*)$        客户主机在地质栏中写入字符不包括换行符
https://    丁香成为的访问协议
${HTTP_HOST}   客户主机请求
$1		$1的值表示^(/.*)$的值
[redirect=301]  临时重定向 302表示永久重定向

这里写图片描述

这里写图片描述

  • 重载apache服务后,地址栏不管输的是localhost还是https://localhost,都重写到了https://localhost

这里写图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值