【发布时间】:2022-01-20 03:40:27
【问题描述】:
我正在尝试使用 docker 容器中的 nginx 将所有 HTTP 流量重定向到 HTTPS。我正在使用docker-compose up 构建 NGINX 容器。在我运行docker-compose up 后,我收到一个错误:
[emerg] 1#1: cannot load certificate "/etc/nginx/etc/nginx/nginx/files/localhost.crt": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/nginx/etc/nginx/nginx/files/localhost.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
下面是我的 nginx.conf
NGINX.conf
http {
upstream flask {
server app:8000;
}
server {
listen 80;
server_name localhost;
}
server {
listen 443 ssl;
server_name localhost;
ssl_certificate etc/nginx/nginx/files/localhost.crt; // this is location of where my certificate is on my local machine
ssl_certificate_key nginx/files/localhost.key;
location / {
proxy_pass http://flask;
proxy_set_header Host "localhost";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
我不知道为什么我会收到“没有这样的文件”的错误。下面是我正在构建和使用的 NGINX 映像的Dockerfile。任何帮助将不胜感激。
NGINX dockerfile
FROM nginx:1.19.2-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY /files/localhost.crt /etc/nginx/nginx/files/localhost.crt
【问题讨论】:
-
关键在您的错误信息中。您在证书和密钥的这些路径的开头缺少用于 root 的斜杠
/。