Fre*_*ers 4 docker lets-encrypt certbot
我试图找到有关在 docker 容器中运行 certbot 的简单文档,但我能找到的只是运行 certbot + web 服务器等的复杂指南。官方页面有点无用... https://hub.docker。 com/r/certbot/certbot/。我已经有与我的网站分开的网络服务器,并且我也想自己运行 certbot。
任何人都可以给我一些关于如何mysite.com使用/opt/mysite/html.
由于我已经在端口 443 和 80 上提供了服务,因此我正在考虑在 certbot 需要时使用“主机网络”,但我不太明白为什么当我的网站已经通过 443 提供服务时它需要访问 443。
我找到了类似的东西来生成 certbot 容器,但我不知道如何“使用它”或告诉它为我的网站生成证书。
例如:
WD=/opt/certbot
mkdir -p $WD/{mnt,setup,conf,www}
cd $WD/setup
cat << 'EOF' >docker-compose.yaml
version: '3.7'
services:
certbot:
image: certbot/certbot
volumes:
- type: bind
source: /opt/certbot/conf
target: /etc/letsencrypt
- type: bind
source: /opt/certbot/www
target: /var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
EOF
chmod +x docker-compose.yaml
Run Code Online (Sandbox Code Playgroud)
这个链接有一些接近我需要的东西,(显然我需要以某种方式给它我的域名作为参数!)
docker run -it --rm \
-v certs:/etc/letsencrypt \
-v certs-data:/data/letsencrypt \
deliverous/certbot \
certonly \
--webroot --webroot-path=/data/letsencrypt \
-d api.mydomain.com
Run Code Online (Sandbox Code Playgroud)
我喜欢让一切都保持“隔离”,所以我希望只让 certbot 在它自己的容器中运行,并配置 nginx/webserver 以单独使用证书,而不是让 certbot 自动配置 nginx 或在与 web 服务器相同的堆栈中运行。
certbot dockerfile给了我一些见解。
基本上,您可以将以下内容附加到您的文件中docker-compose.yaml,就像certbot在 CLI 上附加一样。
请注意“每小时 5 次失败授权的速率限制”并进行测试staging
参见EntrypointDockerFile
ENTRYPOINT [ "certbot" ]
Run Code Online (Sandbox Code Playgroud)
Docker-Compose.yaml:
command: certonly --webroot -w /var/www/html -d www.examplecom -d examplecom --non-interactive --agree-tos -m example@example.com
Run Code Online (Sandbox Code Playgroud)
完整配置示例:
WD=/opt/certbot
mkdir -p $WD/{setup,certbot_logs}
cd $WD/setup
cat << 'EOF' >docker-compose.yaml
version: '3.7'
services:
certbot:
container_name: certbot
hostname: certbot
image: certbot/certbot
volumes:
- type: bind
source: /opt/certbot/certbot_logs
target: /var/log/letsencrypt
- type: bind
source: /opt/nginx/ssl
target: /etc/letsencrypt
- type: bind
source: ${WEBROOT}
target: /var/www/html/
environment:
- 'TZ=${TZ}'
command: certonly --webroot -w /var/www/html -d ${DOMAIN} -d www.${DOMAIN} --non-interactive --agree-tos --register-unsafely-without-email ${STAGING}
EOF
chmod +x docker-compose.yaml
cd $WD/setup
Run Code Online (Sandbox Code Playgroud)
变量:
cat << 'EOF'>.env
WEBROOT=/opt/example/example_html
DOMAIN=example.com
STAGING=--staging
TZ=America/Whitehorse
EOF
chmod +x .env
Run Code Online (Sandbox Code Playgroud)
NGinx:
注意:要使用 SSL 启动 nginx,您需要证书,即使它们是错误的。因此,我将使用旧证书启动 nginx,然后使用 certbot 获取正确的证书,然后重新启动 nginx 加载正确的证书。这仅适用于首次设置。
server {
listen 80;
listen [::]:80;
server_name www.example.com example.com;
location /.well-known/acme-challenge/ {
proxy_pass http://localhost:8575/$request_uri;
include /etc/nginx/conf.d/proxy.conf;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443;
server_name www.example.com example.com;
# ssl_certificate /etc/ssl/live/example.com/fullchain.pem;
# ssl_certificate_key /etc/ssl/live/example.com/privkey.pem;
ssl_certificate /etc/ssl/fake/fake.crt;
ssl_certificate_key /etc/ssl/fake/fake.key;
location / {
proxy_pass http://localhost:8575/;
include /etc/nginx/conf.d/proxy.conf;
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13270 次 |
| 最近记录: |