访问在云服务器上运行的基板前端失败

问题描述

我正在按照本教程开始使用基材 https://substrate.dev/docs/en/tutorials/create-your-first-substrate-chain/

但是,由于我是在云服务器上执行此操作,因此当我尝试在“http://localhost:8000/substrate-front-end-template”上访问前端时, 我必须改为执行“http://my-cloud-ip-address:8000/substrate-front-end-template”。

此前端无法与后端连接,出现以下错误

WebSocket 连接到“ws://my-cloud-ip-address:9944/”失败:连接建立错误:net::ERR_CONNECTION_REFUSED API-WS:与 ws://my-cloud-ip-address:9944:1006 断开连接::异常关闭

基本上,WebSocket 连接在我的服务器上不起作用。如何打开与服务器上运行的基板节点的 WebSocket 连接,以便远程连接可以访问,而不仅仅是本地主机?

注意:我已禁用服务器上的防火墙,所有端口都已打开。

解决方法

最好不要禁用防火墙,而只打开您需要的端口。您可能需要为您的节点设置标志以允许远程访问。下面是一个例子:

./target/release/node-template \
    --telemetry-url 'wss://telemetry.polkadot.io/submit/ 0' \
    --base-path /tmp/node \
    --port 30333 \
    --ws-port 9944 \
    --rpc-port 9933 \
    --rpc-cors all \
    --validator \
    --ws-external \
    --rpc-external \
    --rpc-methods=Unsafe \
    --prometheus-external \
    --name node_validator-TESTING

请注意,不安全标志应仅用于测试,您应根据需要和防火墙设置端口。遥测在这里也是可选的,以及您节点的名称。