Flutter应用程序无法建立具有证书握手错误CERTIFICATE_VERIFY_FAILED的套接字连接

时间:2020-05-07 06:20:10

标签: sockets http flutter ssl ssl-certificate

一个人可能会说这个问题是重复的,但事实并非如此,因为这种类型的其他问题是关于自签名证书和开发环境的。

我有一个来自letsencrypt.org的有效证书,但是我无法建立套接字连接。我有一个nodejs服务器,在其中使用模块“ ws”,并在flutter中使用包“ web_socket_channel”。

我所有的HTTP请求都存在相同的握手问题(使用请求包),但是我可以绕过它,将选项verify设置为false:

 final r = await Requests.get(app_url, verify: false);

我不喜欢这种解决方案,因为它对于生产环境而言并不安全。 我想要一个适合生产环境的解决方案。

谢谢大家

1 个答案:

答案 0 :(得分:0)

对于每一个读到这个的人来说,问题不在于我的颤动代码,而是我的nginx配置,我必须在其中添加以下几行 /etc/nginx/conf.d/sysmon.conf个文件:

location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_http_version  1.1;
        proxy_set_header    Upgrade $http_upgrade;
        proxy_set_header    Connection "upgrade";
        proxy_set_header    Host $http_host;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         http://<SERVER_IP>:<PORT>;
    }