实现HTTPS(Apache+OpenSSL)

简介: https,全称 hypertext transfer protocol secure,安全的超文本传输协议 广泛应用于万维网上安全敏感的通讯
+关注继续查看

实验步骤:

1.开启apache的ssl模块
#取消以下两行的注释
LoadModule ssl_module modules/mod_ssl.so
Include etc/extra/httpd-ssl.conf
2.CA证书申请(实验环境)
#创建存放密钥和证书文件的目录
mkdir /usr/local/apache2/cert && cd /usr/local/apache2/cert

(1)生成服务器私钥,RSA密钥

openssl genrsa -out ca.key 1024

(2)生成csr证书文件,依次输入国家、地区、城市、组织、组织单位、名字或域名、email等

openssl req -new -key ca.key -out ccku.csr

(3)设置证书文件*.crt的有效期等信息

openssl x509 -req -days 365 -sha256 -in ccku.csr -signkey ca.key -out ccku.crt
3.修改配置文件

(1)修改 httpd-ssl.conf文件,调用证书

#vim /usr/local/apache2/etc/extra/httpd-ssl.conf 
#注释掉不安全的协议
#添加:
SSLProtocol all -SSLv2 -SSLv3
#修改加密套件
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
SSLCertificateFile cert/ccku.crt
SSLCertificateKeyFile cert/ca.key

(2)修改apache的主配置文件,添加虚拟主机

<VirtualHost _default_:443>
        DocumentRoot "/usr/local/apache2/htdocs"
        ServerName localhost:443
        SSLCertificateFile cert/ccku.crt
        SSLCertificateKeyFile cert/ca.key
        SSLCertificateChainFile cert/ccku.crt
</VirtualHost>
4.验证

(1)检查配置文件语法

apachectl -t

\#报错提示:

AH00526: Syntax error on line 83 of /usr/local/apache2/etc/extra/httpd-ssl.conf:
SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).

#解决办法:修改主配置文件调用该模块
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so #取消注释

重新检查语法验证
#apachectl -t
Syntax OK

(2)重启apache,使用https测试

apachectl restart
5.强制跳转https
#vim /usr/local/apache2/etc/httpd.conf
#在<Directory "/usr/local/apache2/htdocs">标签下添加:

    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)?$ https//%{SERVER_PORT}/$1 [R=301,L]

6.关闭https的方法:

1.ssl配置文件调用
2.虚拟主机
3.跳转

目录
相关文章
|
8月前
|
Swift 数据安全/隐私保护 iOS开发
iOS开发 - swift通过Alamofire实现https通信
iOS开发 - swift通过Alamofire实现https通信
219 0
iOS开发 - swift通过Alamofire实现https通信
|
8月前
|
开发者 iOS开发
iOS开发 - 用AFNetworking实现https单向验证,双向验证
iOS开发 - 用AFNetworking实现https单向验证,双向验证
268 0
iOS开发 - 用AFNetworking实现https单向验证,双向验证
|
8月前
|
应用服务中间件 程序员 Linux
CentOS 上部署Nginx实现http301重定向https配置文件conf
CentOS 上部署Nginx实现http301重定向https配置文件conf
249 0
|
9月前
|
域名解析 网络协议 安全
nginx配置ssl证书实现https
nginx配置ssl证书实现https
306 0
nginx配置ssl证书实现https
|
9月前
|
Docker 容器
【registry】docker 私有仓库实现https 访问
【registry】docker 私有仓库实现https 访问
263 2
【registry】docker 私有仓库实现https 访问
|
10月前
|
安全 应用服务中间件 网络安全
Nginx HTTPS 实现、自定义 Server 名称及升级 OpenSSL(二)|学习笔记
快速学习 Nginx HTTPS 实现、自定义 Server 名称及升级 OpenSSL
110 0
|
10月前
|
域名解析 弹性计算 缓存
阿里云云计算ACP实验考试之使用负载均衡实现https与http的混合访问(下)
阿里云云计算ACP实验考试之使用负载均衡实现https与http的混合访问(下)
232 0
阿里云云计算ACP实验考试之使用负载均衡实现https与http的混合访问(下)
|
10月前
|
弹性计算 负载均衡 网络协议
阿里云云计算ACP实验考试之使用负载均衡实现https与http的混合访问(上)
阿里云云计算ACP实验考试之使用负载均衡实现https与http的混合访问(上)
240 0
阿里云云计算ACP实验考试之使用负载均衡实现https与http的混合访问(上)
|
10月前
|
存储 安全 网络协议
springboot 配置ssl 实现https访问
springboot 配置ssl 实现https访问
195 0
springboot 配置ssl 实现https访问
|
缓存 安全 数据建模
推荐文章
更多
推荐镜像
更多