使用Nginx Stream搭建 TCP/UDP代理
- Nginx安装1.1如果之前有Nginx可通过如下方式进行清除干净
yum remove nginx
yum clean all
1.2 安装Nginx
Yum update
yum install epel-release
Yum install nginx
1.3 安装成功,可看到Nginx相关配置文件和日志
/etc/nginx/
/var/log/nginx/
1.4 安装Nginx所有模块,包含stream模块
yum -y install nginx-all-modules.noarch
/usr/lib64/nginx/modules/
2.配置
- 配置stream 块和日志
- 备份现有配置文件
cp nginx.conf nginx.conf.bak0
2.2 编辑配置文件
vim nginx.conf
删除http 块所有内容,添加如下stream块
stream {
log_format basic '$remote_addr [$time_local] '
'$protocol $status $bytes_sent '
'$upstream_addr $upstream_bytes_received '
'$upstream_connect_time ';
access_log /var/log/nginx/stream_access.log basic;
error_log /var/log/nginx/stream_error.log;
server{
listen 443;
proxy_pass rdt.lenovo.com:443;
}
}
2.3 保存配置文件后,重新启动nginx服务
systemctl restart nginx
3. 测试代理效果和日志记录