繁体   English   中英

当 nginx 尝试从 docker 容器内部读取 SSL 证书时,权限被拒绝

[英]Permission denied when nginx tries to read SSL certificate from inside docker container

我使用 Certbot 和 Nginx 设置了以下 docker-compose

version: "3"
services:
    web: 
        image: nginx:latest
        user: root
        restart: always
        volumes:
            - ./public:/var/www/html
            - ./conf.d:/etc/nginx/conf.d
            - certbot:/etc/nginx/ssl
            - certbot:/var/www/certbot
        ports:
            - 80:80
            - 443:443

    certbot:
        image: certbot/certbot:latest
        command: certonly --webroot --webroot-path=/var/www/certbot --email email@gmail.com --agree-tos --no-eff-email -d www.domain.com -d domain.com 
        volumes:
            - certbot:/etc/letsencrypt
            - ./logs/certbot:/var/log/letsencrypt
            - certbot:/var/www/certbot

volumes:
     certbot:

Eveything 按预期工作,certbot 创建 SSL 证书并将它们放在正确的位置,以便 Nginx 读取它们。 问题是 Nginx 没有正确的权限来读取在日志中给出以下错误的文件。

2020/12/04 09:50:03 [error] 27#27: *1 cannot load certificate "/etc/nginx/ssl/live/domain.com/fullchain.pem": BIO_new_file() failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen('/etc/nginx/ssl/live/domain.com/fullchain.pem','r') error:2006D002:BIO routines:BIO_new_file:system lib) while SSL handshaking, client: 31.187.58.166, server: 0.0.0.0:443

我正在以用户看到的 root 身份运行 Nginx 映像user: root docker-compose 中的 root 但 Nginx 仍然没有读取此文件的权限。 这怎么可能?

这可能是一条虚假信息。 它“可以”加载证书,但可能无法验证它。 inx:[警告]“ssl_stapling”被忽略,找不到证书的颁发者证书

试试这个 sudo nginx -t nginx 会告诉你到底发生了什么

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM