Nginx转发流量转发——搭建SSR/V2RAY/TROJAN中转节点
1:Nginx安装
1 | yum install -y epel-release && yum install -y nginx |
2:运行Nginx
1 | systemctl start nginx.service |
2.1:设置Nginx转发配置文件
1 | mkdir /etc/nginx/tcp.d/ |
然后输入转发配置:
1 | stream{ |
2.2 在Nginx添加strem目录
1 | cd /etc/nginx/ |
在配置文件中添加以下内容:
1 | # tcp/ip proxy |
或采用echo命令
1 | echo "include /etc/nginx/tcp.d/*.conf;" >> /etc/nginx.conf |
3:用 nginx -t 检查配置
输出
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
3.1 关闭防火墙并禁止开机启动启动防火墙
1 | systemctl stop firewalld.service |
4:设置开机启动nginx
1 | systemctl enable nginx && systemctl start nginx |
5:查看Nginx运行状态
1 | ss -ntlp| grep -i nginx |
6重启Nginx
1 | systemctl restart nginx |
6.1:禁止selinux
1 | sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config |
6.2 若是动态DDNS_NAT/VDS请用定时任务进行更新
执行 crontab -e命令
1 | 0 */12 * * * systemctl restart nginx |
7:检查防火墙状态并开放端口
1 | firewall-cmd --state |
输出running
请运处以下命令放行端口:
1 | firewall-cmd --permanent --add-port=nginx配置的端口号/tcp |
拓展:如何降低国外VPS IP被墙风险
1:启动防火墙
1 | systemctl enable firewalld && systemctl start firewalld |
- 删除之前放行过的ss/ssr/v2ray等端口(如果配置过):
1
firewall-cmd --permanent --remove-port=端口/tcp
- 仅允许国内ip连接该服务器:【gfw探测你的vps,除了ssh、网站等常用端口,ss/ssr/v2ray的端口直接无法连接,被墙概率自然就降低了。】
1
2firewall-cmd --permanent --add-source=国内ip/32
fireawll-cmd --reload
[END]