如何解决如何使用 Nginx 作为在 NanoCurrency 节点上运行的 websocket 的安全反向代理
我有一台运行 Ubuntu 20.04
的服务器,设置了 SSH 密钥,并且我已经使用 Docker 安装了 Nano -
docker run --restart=unless-stopped -d -p 7075:7075/udp -p 7075:7075 -p 127.0.0.1:7076:7076 -p 127.0.0.1:7078:7078 -v /root/nano/:/root --name nano nanocurrency/nano:latest
在 VPS GUI 上,端口 22、443 和 7075 对入站流量开放。
我有一个运行在 WebSocket
上的工作 localhost:7078
,它向终端返回数据流。
Nginx version 1.18.0
已安装,当我运行 systemctl status nginx
时,它声称处于活动状态且没有错误,但是当我尝试从我的笔记本电脑连接时没有任何反应。
这是我的 Nginx 配置 -
server {
listen 443;
# host name to respond to
server_name 000.000.00.000;
location / {
# switch off logging
access_log off;
# redirect all HTTP traffic to localhost:7080
proxy_pass http://localhost:7080;
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 support (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
和 node.js Websocket -
const WS = require('ws');
const ReconnectingWebSocket = require('reconnecting-websocket');
// Create a reconnecting WebSocket.
// In this example,we wait a maximum of 2 seconds before retrying.
const ws = new ReconnectingWebSocket('ws://localhost:7078',[],{
WebSocket: WS,connectionTimeout: 1000,maxRetries: 100000,maxReconnectionDelay: 2000
});
// As soon as we connect,subscribe to block confirmations
ws.onopen = () => {
const subscription = {
"action": "subscribe","topic": "confirmation"
}
ws.send(JSON.stringify(subscription));
};
// The node sent us a confirmation
ws.onmessage = msg => {
console.log(msg.data);
if (msg.data.topic === "confirmation") {
console.log ('Confirmed',data.message.hash)
}
};
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com(将#修改为@)