我使用docker compose设置了一个nginx容器,该容器使用在主机上生成的证书。但是当我运行它时,它告诉我找不到证书。
错误信息如下:
nginx | nginx: [emerg] SSL_CTX_use_PrivateKey_file("/etc/letsnecrypt/live/example.com/privkey.key") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsnecrypt/live/example.com/privkey.key','r') error:20074002:BIO routines:file_ctrl:system lib error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib)
但是,当我使用“docker-compose run nginx /bin/bash”进入容器并转到证书文件夹时,它们确实存在。
那么为什么会出现这个错误呢?
我的nginx配置文件:
docker-compose.yml:
版本:'3.5'
错误信息如下:
nginx | nginx: [emerg] SSL_CTX_use_PrivateKey_file("/etc/letsnecrypt/live/example.com/privkey.key") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsnecrypt/live/example.com/privkey.key','r') error:20074002:BIO routines:file_ctrl:system lib error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib)
但是,当我使用“docker-compose run nginx /bin/bash”进入容器并转到证书文件夹时,它们确实存在。
那么为什么会出现这个错误呢?
我的nginx配置文件:
server {
listen *:443;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsnecrypt/live/example.com/privkey.key;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
access_log /dev/stdout upstreamlog;
error_log /dev/stderr debug;
}
docker-compose.yml:
版本:'3.5'
services:
nginx:
container_name: nginx
image: nginx
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./nginx.default:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt:/etc/letsencrypt