'LibreSSL SSL_connect: SSL_ERROR_SYSCALL' 在 curl 到 Docker 容器上的 NGINX 反向代理

Ken*_*yen 5 ssl docker nginx-reverse-proxy

我能够在启用 SSL 的情况下成功地获得在本地运行的 NGINX 反向代理。但是,一旦我尝试让它在 Docker 容器上运行,我就会遇到 SSL 问题。

我使用 .portforwarded 到端口 9443 docker run -it nginxProxy -v local_path_to_certs:container_path_to_certs -p 9443:443

我的 Dockerfile:

FROM nginx:alpine

# Expost port 443
EXPOSE 443

RUN rm -v /etc/nginx/nginx.conf
RUN rm -rf /etc/nginx/conf.d

# Copy custom configuration file from the current directory
COPY nginx.conf /etc/nginx/nginx.conf

ENTRYPOINT [ "nginx", "-c", "/etc/nginx/nginx.conf", "-g", "daemon off;"]
Run Code Online (Sandbox Code Playgroud)

我的 nginx.conf:

events {
    worker_connections 1024;
}


http {

  ssl_session_cache  builtin:1000  shared:SSL:10m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4:!SHA:!SHA1:!SSLv2:@STRENGTH;
  ssl_prefer_server_ciphers on;

  ssl_certificate           /path_to_cert/public.cert.pem;
  ssl_certificate_key       /path_to_private_key/private.key.pem;
  ssl_password_file         /path_to_password_file/password.txt;

  server {
    listen [::]:443 ssl;

    server_name _;

    location / {
       proxy_pass https://example.com; 

    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的本地机器上,这和预期的一样好,但是在 Docker 容器上运行时运行curl https://localhost:9443 -vvv给了我

* Rebuilt URL to: https://localhost:9443/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:9443 
* Closing connection 0
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:9443 
Run Code Online (Sandbox Code Playgroud)

小智 0

我假设你现在已经解决了这个问题。不管怎样,我都会留下我找到的解决方案来寻找同样的问题。我遇到了类似的错误,用户 mljrg 发现当主机名解析为 IPv6 地址时会发生这种情况。他通过比较两台机器的输出发现了这一点,一台机器解析为 IPv4,它在那里工作,另一台解析为 IPv6,它在那里失败。

因此,解决方案是在 macOS High Sierra 10.13.6 上运行 networksetup -setv6off Wi-Fi。

也许这对像我这样的其他人有帮助。