nginx和奇偶校验的Websocket连接



我在云服务器上运行DAPP,并使用启用Wesocket的Nginx和Parity客户端。

我为HTTPS域安装了Certbot证书。现在我有问题的是,在使用HTTP访问我的网站时,它在Chrome上出现了一个错误。

  web3-providers.umd.js:1269 Mixed Content: The page at 'https://www. 
  chain.com/' was loaded over HTTPS, but attempted to connect to the 
 insecure WebSocket endpoint 'ws://40.138.47.154:7546/'. This request has 
   been blocked; this endpoint must be available over WSS.

然后,我在nginx配置文件上添加了反向代理作为

location / {
         # switch off logging
   access_log off;
    proxy_pass http://localhost:7556; #Port for parity websocket
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # WebSocket 
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

然后给出一个错误

" WebSocket接口处于活动状态。打开WS连接到访问RPC。"

这里有什么问题,我应该尝试什么?

谢谢

https不允许在页面上加载不安全的内容。

一种可能的解决方案是在应用程序服务器和客户端之间使用SSL/TLS终结器。

从官方的nginx文档中,配置文件的相关部分可能是这样:

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}
upstream websocket {
    server localhost:7546;
}
server {
    listen 443; 
    
    location / {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
    }
    ssl on;
    # specify cert and key
}

在DAPP内部将'ws://40.138.47.154:7546/'更改为wss://40.138.47.154

最新更新