区块链节点网络的nginx转发部署
sudo apt-get install nginx
查看nginx安装是否带with-stream参数
nginx -V |grep with-stream
有with-stream参数,可以代理tcp协议。区块链节点间的P2P通讯协议为TCP,所以nginx需要用支持TCP转发的版本
修改nginx主配置文件
vim /etc/nginx/nginx.conf
在文件后添加,示例为两个区块链节点之间转发的配置
stream{
upstream node1{
server 192.168.6.226:26656 max_fails=3 fail_timeout=10s;
}
upstream node2{
server 192.168.6.227:26656 max_fails=3 fail_timeout=10s;
}
server{
listen 10001;
proxy_connect_timeout 20s;
proxy_timeout 5m;
proxy_pass node1;
}
server{
listen 10002;
proxy_connect_timeout 20s;
proxy_timeout 5m;
proxy_pass node2;
}
}
其中10001,10002,加上nginx所在服务器的ip,配置给区块链节点的对外地址。种子节点的地址也要配置为nignx的地址加分配的端口。
例如:nginx主机ip为 192.168.6.228 开放10001,10002给节点node1,node2。
node1主机ip为 192.168.6.226 开放 26656, 其config.toml的 external_address = "192.168.6.228:10001"
node2主机ip为 192.168.6.227 开放 26656,其config.toml的 external_address = "192.168.6.228:10002",
测试配置文件是否正确
nginx -t -c /etc/nginx/nginx.conf
启动nginx服务
systemctl start nginx.service
查看启动的nginx服务
systemctl status nginx.service
若出现 nginx Failed to read PID from file /run/nginx.pid: Invalid argument 的报错,
mkdir -p /etc/systemd/system/nginx.service.d
printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
然后
systemctl daemon-reload
systemctl restart nginx.service
测试nginx的连通性
$ telnet 192.168.6.228 10001
Trying 192.168.6.228...
Connected to 192.168.6.228.
Escape character is '^]'.
出现"Connected to 192.168.6.228",说明连接成功
----------------陌上阡头,草长莺飞-----------------
https://www.cnblogs.com/tyche116/