Skip to content

写个docker+nginx部https的模板

封面:

背景

有时候想部署一个给国内朋友使用的小网站,但是国内又没有像国外那些免费好用的部署平台,所以就只能自己搭建,自己搭建又每次避开不了nginx反代实现https这一步,所以就简单写了个模板以及shell脚本,方便自己每次快速部署。

简介

模板地址,一个基于nginx + dockerhttps模板,可以快速部署https网站🚀🚀🚀

你至少并且也只需要拥有docker环境,# 如何在 Ubuntu 20.04 上安装和使用 Docker

基本流程:

使用该模板

  1. 进入你的repos目录,可以为任意目录(不过后续可能要稍做修改),这里以/root/repos/为例,如果没有repos目录,可以创建一个。然后clone本项目
shell
cd /root/repos/
shell
git clone https://github.com/Justin3go/nginx-https-template.git
cd nginx-https-template
  1. 替换cert/下的证书为你的证书,格式为your-domain.keyyour-domain.pem,比如我的域名是justin3go.com,那么我的证书就是justin3go.com.keyjustin3go.com.pem

  2. 运行脚本./scripts/replace-domain.sh --domain=your-domain

shell
sudo chmod -R +x ./scripts # 设置脚本权限
./scripts/replace-domain.sh --domain=your-domain # 运行脚本替换域名

注意:默认https转发的是80端口,如果你的网站不是80端口,需要修改/conf.d/default.conf中的proxy_pass为你的端口

  1. 如果在第一步中你使用的自定义目录,则修改docker-compose.yml中的根目录为你的目录,默认为/root/repos/

  2. 启动容器

shell
./scripts/run.sh

接下来

  • 你可以使用docker ps命令查看容器是否正常运行
  • 以及使用tail -n 1000 logs/access.logtail -n 1000 logs/error.log查看nginx运行日志