[英]nginx redirect http to https in docker container connection refused
[英]Redirect http to https nginx in docker container
我正在嘗試使用 Z05B6053C158A213EZ4DAFC3 容器中的 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;
}
}
}
我不知道為什么我會收到“沒有這樣的文件”的錯誤。 下面是我正在構建和使用的Dockerfile
圖像的 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
像這樣的東西就是你要找的東西。
http {
upstream flask {
server app:8000;
}
server {
listen 80;
server_name localhost;
return 301 https://$server_name$request_uri;
}
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 /etc/nginx/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;
}
}
}
您還需要復制密鑰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.