无法通过 docker-letsencrypt-nginx-proxy-companion 启用 ssl



我想通过docker-letsencrypt-nginx-proxy-companion启用ssl。这是docker-compose.yml

version: "3.3"
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- certs:/etc/nginx/certs:ro
- vhostd:/etc/nginx/vhost.d 
- html:/usr/share/nginx/html 
- /var/run/docker.sock:/tmp/docker.sock:ro  
restart: always
db:
# ---
wordpress:
# ---
environment:
# ---
VIRTUAL_HOST: blog.ironsand.net
LETSENCRYPT_HOST: blog.ironsand.net
LETSENCRYPT_EMAIL: mymail@example.com
restart: always
letsencrypt-nginx-proxy-companion: 
container_name: letsencrypt
image: jrcs/letsencrypt-nginx-proxy-companion 
volumes: 
- certs:/etc/nginx/certs 
- vhostd:/etc/nginx/vhost.d 
- html:/usr/share/nginx/html 
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
NGINX_PROXY_CONTAINER: nginx-proxy
restart: always
networks:
default:
external:
name: nginx-proxy
volumes:
certs:
vhostd:
html:

docker logs letsencrypt表示证书已经存在。

/etc/nginx/certs/blog.ironsand.net /app
Creating/renewal blog.ironsand.net certificates... (blog.ironsand.net)
2020-04-09 00:03:23,711:INFO:simp_le:1581: Certificates already exist and renewal is not necessary, exiting with status code 1.
/app

但ACME挑战一无所获。(故障?(

$ docker exec letsencrypt bash -c 'echo "Hello world!" > /usr/share/nginx/html/.well-known/acme-challenge/hello-world'
$

端口443正在列出,但该端口已从外部关闭。

// in remote server
$ sudo lsof -i:443
[sudo] password for ubuntu:
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 10910 root    4u  IPv6 633694      0t0  TCP *:https (LISTEN)
// from local pc
❯ nmap -p 443 blog.ironsand.net
Starting Nmap 7.80 ( https://nmap.org ) at 2020-04-09 09:44 JST
Nmap scan report for blog.ironsand.net (153.127.40.107)
Host is up (0.035s latency).
rDNS record for 153.127.40.107: ik1-418-41103.vs.sakura.ne.jp
PORT    STATE  SERVICE
443/tcp closed https
Nmap done: 1 IP address (1 host up) scanned in 0.21 seconds

我使用数据包过滤,但它对80和443是开放的,我不使用防火墙。如何进一步调查问题所在?

我不能直接解决你的问题,但我可以写一些提示,所以可以解决你的麻烦。

  1. 您的命令不返回任何内容
    bash -c 'echo "Hello world!" > /usr/share/nginx/html/.well-known/acme-challenge/hello-world'
    此命令只向该位置写入"Hello world!",通常不返回任何内容。看见https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Redirections

  2. 查看certs文件夹内部
    看看certs文件夹,也许可以把它们清理干净。检查文件夹是否正确安装在nginx容器中。对容器进行bash操作,然后检查ssl文件夹。

  3. 检查防火墙是否没有中断
    外部是否可能没有连接?里面是什么?登录你的docker主机并从那里检查连接(可能opensslcurl是你的朋友(,

  4. 不要在容器内使用SSL
    当sobody尝试将ssl与ACME映像和"野生装载和共享卷"一起使用时,我经常看到问题。但我从来没有听说过问题,当同样的人使用正常的反向代理时。我在下面解释一个好的设置。

因此,只需从容器中删除整个letscrypt代码,并关闭容器的443端口
(此外,您可以切换到非根映像,并且只公开不需要根权限的端口。(然后在主机上安装nginx,并设置一个反向代理(类似于proxy_pass 127.0.0.1:8080(。现在安装certbot并启动它。它对您有帮助,而且是直接的
certbot还可以维护您的证书。

最新更新