云服务器建站教程:云服务器部署 SSL 证书 -Apache

基于Centos-7.2部署LAMP环境所搭建的 apache 环境,为 web 服务配置 SSL 证书(需要提前准备好域名)。以下步骤为配置部署证书的全部过程。
1.下载证书并解压
进入百度智能云控制台--安全和管理--SSL 证书服务–已购证书列表中,点击之前基于该服务器所绑定域名申请的证书信息--查看证书。

点击下载证书,选择 PEM_Apache 格式,并设置四位数字的解压缩密码。

在本地下载完毕后,双击打开,可看到有 cer、crt 以及 key 三个文件,选择解压到,设置路径后,输入刚在控制台上设置的四位数密码。

2.上传证书文件到服务器中
使用 FTP 或者其他工具将上一步中解压得到的 cer、crt 以及 key 文件上传到服务器的 apche 配置目录/etc/httpd/conf 中

3.安装 mod_ssl,并配置证书
因为是使用 yum 直接安装的 apache,无法在安装的时候,直接编译添加 ssl 模块,需要再进行安装。
yum install mod_ssl openssl
安装之后,在/etc/httpd/conf.d 下多了一个 ssl.conf 文件。
vim /etc/httpd/conf.d/ssl.conf
搜索 ServerName 取消该行的注释,并修改域名为证书域名。
将证书三个文件的位置路径填写正确

重启 httpd 后,可通过https://域名打开该网站
4.http 强制跳转 https
因为是 yum 安装的,在 apache 的配置文件中没有 ssl.so 和 httpd-ssl.conf 模块路径,可手动添加 rewrite 规则实现。
vim vim /etc/httpd/conf/httpd.conf
在<Directory>
中添加:

再次重启 apache 后,访问网站时,http 会强制跳转到 https。
版权声明: 本文为 InfoQ 作者【百度开发者中心】的原创文章。
原文链接:【http://xie.infoq.cn/article/6453e5fd33da91dd86ad68006】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
评论