Docker & docker-compose 搭建本地 https 环境
工具:
- acme#sh (生成免费证书)
- Docker & docker-compose
- ihost (可以手动修改 hosts 文件)
配置文件:
docker-compose.dev.yml
version: '3'
services:
proxy:
image: nginx:stable-alpine
ports:
- 443:443
volumes:
- /Users/thonatos/.acme.sh/*.implements.io:/etc/nginx/ssl/
- ./default.conf:/etc/nginx/conf.d/default.conf
default.conf
# HTTP server
#
server {
listen 443 ssl;
server_name szcu.implements.io;
ssl_certificate /etc/nginx/ssl/fullchain.cer;
ssl_certificate_key /etc/nginx/ssl/*.implements.io.key;
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://192.168.2.51:7001; # IP 请勿使用 127.0.0.1
}
}
hosts
127.0.0.1 szcu.implements.io
运行
# 启动 Egg.js
yarn dev
# 启动 nginx
docker-compose -f docker-compose.dev.yml up
打开 Chrome 可以看到旁边绿色的锁了,大功告成。