本文发布于 1189 天前,部分信息可能随时间变化。
1、设置防火墙规则
ufw disable
2、更新并安装Nginx
apt update
apt install nginx -y
3、启动Nginx
service nginx start
- 双击打开nginx.conf文件,添加以下代码
stream {
upstream tcp_proxy {
hash $remote_addr consistent; #确保同一个客户端的请求总是被分配到同一个后端服务器上
server 服务器域名或IP:节点端口; #A服务器域名
server 服务器域名或IP:节点端口; #B服务器域名
}
server {
listen 1024; #本机放行的端口
proxy_connect_timeout 1s;
proxy_timeout 60s;
proxy_pass tcp_proxy;
}
}
4、重启Nginx
service nginx restart
5、各种玩法设置
- 轮转:请求轮流转发到应用服务器;
- 加权轮转:按照分配的权重转发请求到应用服务器;在端口后面加 weight=X
- least_conn:分配给连接数最少的应用服务器;写法:least_conn;
- ip hash:根据客户端IP地址来确定应用服务器。写法:ip hash;










