nginx 转发流量
nginx转发是个好东西,貌似比iptables更优秀?
中转机器:
首先安装nginx:
yum install -y epel-release && yum install -y nginx
配置nginx,编辑配置文件,加入转发配置:
vi /etc/nginx/nginx.conf
stream {
server {
listen 端口号; # 端口号改成1-65535中的任意一个数字,例如8081
proxy_pass 境外ip:境外端口号; # 用境外ip和端口号替换
}
}
检查配置是否有错:
nginx -t
输出如下则表示成功:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
设置开机启动并启动nginx:
systemctl enable nginx && systemctl start nginx
查看防火墙:
firewall-cmd --state
如果运行,放行对应端口:
firewall-cmd --permanent --add-port=nginx中配置的端口号/tcp
fireawll-cmd --reload
如果不在运行,开启并开机启动:
systemctl enable firewalld && systemctl start firewalld
禁用selinux:
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
setenforce 0
查看端口是否监听:
ss -ntlp
查看防火墙是否放行端口:
firewall-cmd --list-all
被中转机器:
目的是为了除了ssh的22端口,网站的80/443端口,其他端口只允许国内服务器连接
安装nginx:
yum install -y epel-release && yum install -y nginx
编辑替换默认页内容:
/usr/share/nginx/html
启动防火墙:
systemctl enable firewalld && systemctl start firewalld
删除之前放行的SS/ssr/v2ray等端口:
firewall-cmd --permanent --remove-port=端口/tcp
仅允许中转机器访问:
firewall-cmd --permanent --add-source=国内ip/32
fireawll-cmd --reload
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
setenforce 0