『中级篇』docker之wordpress容器SSL(番外篇)(78)

发布时间:2020-04-22 04:19:22 作者:IT人故事
来源:网络 阅读:272

原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!
原文链接地址:『中级篇』docker之wordpress容器SSL(番外篇)(78)

搞了2天终于搞定了,现在分享给大家。 apache2 容器内安装SSL实现wordpress证书安装。

前提

『中级篇』docker容器安装wordpress(37) 通过上边的方式已经安装了wordpress 和mysql ,可以正常的访问

准备工作


* 容器安装vi 和 rz

apt-get update
#编辑文件使用
apt-get install vim
#从阿里或者腾讯云,华为云申请的证书上传
apt-get install lrzsz


* 证书上传

cd /etc/apache2
mkdir ssl
cd /etc/apache2/ssl
rz
#将华为云的三个证书上传到这个目录下

![](https://upload-images.jianshu.io/upload_images/11223715-cd70cc200fc9b0c5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

* 配置/etc/apache2/sites-enabled/default-ssl.conf

#如果没有的话从/sites-available里面复制过去
cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf
#修改文件
vi /etc/apache2/sites-enabled/default-ssl.conf

>按照我的进行修改。红色指的这几个修改下

![](https://upload-images.jianshu.io/upload_images/11223715-e00070dbb4b651a1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

* 检查配置

查看apache2/sites-enabled目录下是否存在default-ssl.conf,
查看apache2/mods-enabled目录下是否存在ssl.conf、ssl.load
如果存在,那就说明没问题了,如果不存在的话,从相应的sites-available目录下复制进去。

* http请求强制跳转到https

vi /etc/apache2/sites-available/000-default.conf

增加下面的配置

ServerAdmin webmaster@
DocumentRoot /var/www/html
<Directory "/var/www/html"> 
RewriteEngine   on
RewriteBase /

FORCE HTTPS

RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</Directory>

![](https://upload-images.jianshu.io/upload_images/11223715-32fbbc625d70a18e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

 * 重启apache

service docker restart


### docker wordpress容器增加端口
* 找到wordpress容器

cd /var/lib/docker/containers

![](https://upload-images.jianshu.io/upload_images/11223715-ae45cfd88c1ea0bb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

* 为了防止你眼花弄错 先备份

cp config.v2.json config.v2.json_bak
cp hostconfig.json hostconfig.json_bak

![](https://upload-images.jianshu.io/upload_images/11223715-648cd4154d10d24b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

* 停止docker

systemctl stop docker 或者 service docker stop


* 修改增加端口
>原来只有80 我增加了443

vi hostconfig.json


![](https://upload-images.jianshu.io/upload_images/11223715-cd9644b0d6d3f09b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

>原来只有80 我增加了443

vi config.v2.json


![](https://upload-images.jianshu.io/upload_images/11223715-332ed7d80fab4a59.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

* 保存之后启动docker
> 增加了443

systemctl start docker



![](https://upload-images.jianshu.io/upload_images/11223715-3f151e646e1bdc8a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

### 安全组中增加443

![](https://upload-images.jianshu.io/upload_images/11223715-f7dc826fa5c227a8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

### 安装插件
>只需要这2个插件

![](https://upload-images.jianshu.io/upload_images/11223715-e338ebe7eb275d22.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

### 终于搞定
>输入:idig8.com自动跳转

![](https://upload-images.jianshu.io/upload_images/11223715-338387d705c598be.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

PS:在云主机多亏了备份,有几次一不小心都差点起不来了自己写的文章都白费了,一定要给机器备份后在弄,防止你的一个字母写错满盘皆输。参考https://peter.pudaite.net/2017/05/29/enabling-https-on-the-standard-wordpress-docker-image/ 老外写的很稳

![](http://upload-images.jianshu.io/upload_images/11223715-3407e1c7ac8d7935?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
推荐阅读:
  1. 『高级篇』docker之CICD(终结篇)(44)
  2. 『高级篇』docker之镜像仓库(20)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

docker 开发 镜像

上一篇:VMware中ubuntu找不到共享文件夹

下一篇:android编译错误

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》