【发布时间】:2021-06-14 19:01:12
【问题描述】:
我正在尝试将 NGINX 用作具有 next.js 前端和 FastAPI 后端的代理,每个后端都在自己的容器中运行。
我在使用 HTTP 时一切正常,但在使用 HTTPS 时遇到了一些问题。
所有容器都开始运行,没有任何问题,一切似乎都在工作,但是当我尝试与代理通信时,我收到以下错误:
From host:
lafton@lafton-platform:~$ curl localhost -L
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:443
Form inside NGINX container using localhost:
root@6016e75698cf:/# curl localhost -L
curl: (60) SSL: no alternative certificate subject name matches target host name 'localhost'
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
From inside NGINX container using lafton.io:
root@6016e75698cf:/# curl https://lafton.io
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to lafton.io:443
我尝试在本地而不是在 Docker 中安装 NGINX,它按预期工作。我尝试启用在默认配置中注释掉的 SSL 配置,它在本地与 SSL 完美配合。
然后我尝试在我的设置中使用默认 SSL 配置,但它不起作用。 这是我在 /etc/nginx/nginx.conf 中运行的 NGINX 配置
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
load_module /etc/nginx/modules/ngx_http_js_module.so;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name lafton.io;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name lafton.io;
ssl_certificate /etc/certs/fullchain1.pem;
ssl_certificate_key /etc/certs/privkey1.pem;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://lafton-website:3000;
}
location /api/albums {
proxy_pass http://lafton-albums:8000;
}
}
}
端口 80 部分只是对 https 的重定向。没有它也是一样的。 密码来自 Mozilla 的建议。我尝试将其更改为默认设置,因为我所做的一些故障排除似乎表明没有匹配的密码。
我真的迷路了,不知道在哪里寻找进一步的故障排除。任何帮助将不胜感激!
【问题讨论】:
-
简单问题:您的容器是向主机公开 443 还是仅公开 80?容器内部的
curl将仅与curl -L -k一起使用以接受非 CN 匹配的证书。我猜你的证书 CN 是lfton.io而不是 localhost。通过添加-k确保您正在接受使用 curl 的不受信任的 TLS 连接,然后重试。 -
这很尴尬...您对
curl -L -kpart 的看法是正确的。我一使用它,它就从容器内部开始工作。谢谢你的提示!我确信容器暴露了端口 443,但我现在看到我输入了 433。由于我无法让它在容器内工作,我非常确定问题出在容器内。非常感谢您的帮助!