当前位置: 首页 > news >正文

手机淘宝客网站怎么做的网页设计制作实训报告模板

手机淘宝客网站怎么做的,网页设计制作实训报告模板,网站开发面板,资金盘网站开发公司哪里好极简 Docker Compose Nginx Certbot 自动化 HTTPS 部署指南 简要:打造属于您的全自动 HTTPS 服务,无需复杂配置,无需手动维护,只需 3 个核心文件和 5 分钟时间,即可实现永久自动化的 HTTPS 加密解决方案(适用于个人项…

极简 Docker Compose + Nginx + Certbot 自动化 HTTPS 部署指南

简要:打造属于您的全自动 HTTPS 服务,无需复杂配置,无需手动维护,只需 3 个核心文件和 5 分钟时间,即可实现永久自动化的 HTTPS 加密解决方案(适用于个人项目、测试项目)。
标签:Docker, Nginx, HTTPS, Certbot, 自动化

引言:三文件搞定 HTTPS 自动化部署

本文将展示如何仅用三个配置文件和 Docker Compose 实现:

  1. 全自动 HTTPS 证书管理
  2. HTTP 自动重定向到 HTTPS
  3. 零干预证书续期
  4. 极简目录结构

无需复杂脚本,无需额外工具,只需以下结构:

/home/middleware/nginx/
├── conf.d/
│   ├── default.conf    # HTTP 处理
│   └── ssl.conf        # HTTPS 服务配置
├── nginx.conf          # 主配置
├── docker-compose.yml  # 服务编排
└── cert/               # 证书存储目录

1. 创建目录结构

mkdir -p /home/middleware/nginx/{conf.d,cert}
cd /home/middleware/nginx

2. 配置文件内容

2.1 nginx.conf (主配置文件)

user  nginx;
worker_processes  auto;error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;events {worker_connections  1024;
}http {include       /etc/nginx/mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile        on;keepalive_timeout  65;# 包含其他配置include /etc/nginx/conf.d/*.conf;
}

2.2 conf.d/default.conf (HTTP 处理)

# 处理 HTTP 请求
server {listen 80;server_name example.com www.example.com;# Certbot 验证目录location /.well-known/acme-challenge/ {root /var/www/certbot;}# 其他所有请求重定向到 HTTPSlocation / {return 301 https://$host$request_uri;}
}

2.3 conf.d/ssl.conf (HTTPS 服务)

# HTTPS 服务器
server {listen 443 ssl http2;server_name example.com www.example.com;# SSL 证书配置ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;# 安全配置ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256';ssl_session_cache shared:SSL:10m;ssl_session_timeout 1d;# 安全头add_header Strict-Transport-Security "max-age=63072000" always;# 你的应用配置 (如果是已有的网站这里可配置代理跳转)location / {root /usr/share/nginx/html;index index.html;}# 保留证书验证路径location /.well-known/acme-challenge/ {root /var/www/certbot;}
}

2.4 docker-compose.yml (服务编排)

version: '3.8'services:nginx:image: nginx:alpinecontainer_name: nginxports:- "80:80"- "443:443"volumes:- ./nginx.conf:/etc/nginx/nginx.conf- ./conf.d:/etc/nginx/conf.d- ./cert:/etc/letsencrypt- certbot_www:/var/www/certbotrestart: unless-stoppeddepends_on:- certbotcertbot:image: certbot/certbot:latestcontainer_name: certbotvolumes:- ./cert:/etc/letsencrypt- certbot_www:/var/www/certbotcommand: >sh -c '# 首次运行获取证书if [ ! -f "/etc/letsencrypt/live/example.com/fullchain.pem" ]; thencertbot certonly --webroot -w /var/www/certbot -d example.com -d www.example.com --email your-email@example.com --agree-tos --noninteractive;fi;# 每12小时检查续期while :; dosleep 12hcertbot renewdone'restart: unless-stoppedvolumes:certbot_www:

3. 部署流程

步骤1: 替换域名

将配置文件中的所有 example.com 替换为你的实际域名

步骤2: 启动服务

docker-compose up -d

步骤3: 验证部署

curl -I https://yourdomain.com
# 应返回 200 OK

4. 工作原理

证书生命周期管理

  1. 首次启动

    • Certbot 检测到没有证书
    • 自动通过 HTTP 验证获取证书
    • 证书保存在 ./cert 目录
  2. 自动续期

    • Certbot 每12小时检查证书
    • 到期前30天内自动续期
    • Nginx 自动使用新证书

请求流程

  1. HTTP 请求到达 80 端口
  2. 如果是证书验证请求 → 由 Certbot 处理
  3. 其他请求 → 重定向到 HTTPS
  4. HTTPS 请求使用有效证书提供服务

5. 常见问题解决

问题1: 首次启动证书获取失败

解决方案:重启服务

docker-compose down
docker-compose up -d

问题2: 需要更新配置

# 修改配置后
docker-compose down
docker-compose up -d --force-recreate

问题3: 检查证书状态

docker-compose exec nginx openssl x509 -in /etc/letsencrypt/live/yourdomain.com/fullchain.pem -noout -dates

6. 进阶调整

自定义证书参数

docker-compose.yml 中修改 Certbot 命令:

command: >sh -c 'if [ ! -f "/etc/letsencrypt/live/example.com/fullchain.pem" ]; thencertbot certonly --webroot -w /var/www/certbot -d example.com --email your-email@example.com --agree-tos --noninteractive--rsa-key-size 4096; # 密钥大小fi;while :; do sleep 12h; certbot renew; done'

多域名支持

command: >sh -c 'if [ ! -f "/etc/letsencrypt/live/example.com/fullchain.pem" ]; thencertbot certonly --webroot -w /var/www/certbot -d example.com -d www.example.com -d api.example.com; # 添加更多域名fi;while :; do sleep 12h; certbot renew; done'

测试环境使用

command: >sh -c 'if [ ! -f "/etc/letsencrypt/live/example.com/fullchain.pem" ]; thencertbot certonly --webroot -w /var/www/certbot -d example.com --staging; # 使用测试环境fi;while :; do sleep 12h; certbot renew; done'

结语:极简 HTTPS 自动化

通过这个方案,你获得了:

  • 极简配置:仅需三个核心文件
  • 全自动化:证书获取、续期零干预
  • 易于维护:所有配置集中管理
  • 资源高效:轻量级容器方案

立即部署

  1. 创建目录结构
  2. 复制配置文件
  3. 替换域名
  4. 运行 docker-compose up -d

最佳实践

  • 定期执行 docker-compose pull 更新镜像
  • 监控 ./cert 目录的证书文件
  • 每季度检查一次部署状态

这种极简但功能完整的 HTTPS 解决方案,完美平衡了易用性和功能性,适合大多数 Web 应用场景。

资源链接

  • Nginx 官方镜像
  • Certbot 文档
  • Let’s Encrypt 官方文档
  • SSL Labs 测试工具
  • 在线证书链检查器

如有任何问题,欢迎在评论区交流讨论!
作者涉猎范围广泛,有技术问题可有偿提供技术支持!

http://www.dtcms.com/a/458112.html

相关文章:

  • 11.1 kubectl命令行工具
  • SSM房屋租赁管理系统d97n3(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
  • 不备案的网站需要注销吗优化大师 win10下载
  • 做盗链网站八大员继续教育入口
  • 长春网站建设首选网诚传媒_正规网站建设服务中心
  • 网站开发和软件开发区别怎么做宣传
  • 牢七的Java之旅6
  • Eclipse集成开发环境的使用
  • 免费个人网站怎么做不免费的网络营销方式
  • 秦皇岛网站建设系统推荐西部数码网站管理助手v3.0
  • 浙江网站建设广告语wordpress图片文章
  • 佛山网页网站设计个人电台网站模版
  • 360提示危险的网站在线文档 wordpress
  • 电商网站策划做翻译网站 知乎
  • 广州网站建设网站开发贵阳seo网站管理
  • 【LeetCode】54. 螺旋矩阵
  • 零基础学Docker(7)--Docker网络
  • 网站关键词掉的很快中卫网站推广公司
  • 32套网站后台管理系统模板开发一款软件的费用
  • DVWA靶场之十五:授权绕过(Authorisation Bypass)
  • wordpress菜单参数设置seo线上培训机构
  • FPGA实现直流电机转速、电压、电流测量系统(基于EP4CE6F17C8 + INA226)
  • 【linux】 查看cpu占用前10的进程
  • 跨越银色浪潮:中国智慧养老的“无人区”探索与人性回归
  • 如何做网上私人彩票网站网站建站公司官网
  • 网站管理员功能网站推广的目的是什么
  • 网站建设书籍免费wordpress超精简主题
  • 上海市建设安全协会网站孟 侠上海网站建设优化公司
  • c++ 程序基础-变量赋值
  • 吴恩达机器学习课程(PyTorch 适配)学习笔记:2.3 PyTorch 工具与高效实现