编程技术分享平台

网站首页 > 技术教程 正文

通过docker部署nginx和https(如何搜索docker的nginx镜像)

xnh888 2024-10-03 04:42:07 技术教程 22 ℃ 0 评论


通过docker部署nginx和https操操作步骤


1: 注意

以下操作请确保安装了docker和docker-compose

2: 将所有文件clone到/home/nginx目录下,在/home目录下创建logs文件夹

$ cd /home
$ git clone https://github.com/hypwxm/docker-nginx-https.git
$ mv docker-nginx-https nginx
$ mkdir /home/logs

3: 配置和修改执行文件权限

* 修改/home/nginx/letencrypt下的renew.sh中的LIST=('域名1' '域名2'),email改成自己的

$ sudo chmod +x /home/nginx/letsencrypt/renew.sh

4: 在/home/nginx/conf.d下添加配置文件,这一步先不要配置证书相关的信息,因为此刻证书还未生成

5: 启动nginx,如果要修改目录挂载,请修改docker-compose.yml文件

$ cd /home/nginx
$ docker-compose up -d

6: 配置或更新https证书

$ cd /home/nginx/letsencrypt
$ docker build -t certbot:1.0 .
$ /home/nginx/letsencrypt/renew.sh

7: 证书更新成功,给/home/nginx/conf.d下的配置文件中添加证书配置

8: 重启nginx,使证书配置生效,以下两种方式均可

$ docker restart nginx-gateway
$ docker exec -it $containerId nginx -s reload

9: 如果证书要过期了,请用以下命令更新

$ /home/nginx/letsencrypt/renew.sh

10: 通过linux的定时任务,配置定时更新https证书

$ crontab -e

从给点的选项里面选一个自己习惯的编辑软件,打开定时任务文件

在文件的末尾加上

$ 0 0 1 * * /home/nginx/letsencrypt/renew.sh
$ 0 1 1 * * docker exec nginx-gateway nginx -s reload

每月一号定时更新证书,更新完成一小时后,重启nginx加载更新后的证书

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表