Press "Enter" to skip to content

使用Nginx转发TCP

一.实现过程:
1.安装nginx,stream模块默认不安装的,需要手动添加参数:–with-stream
2.nginx.conf 配置,参考说明:ngx_stream_core_module
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
.................
}

# tcp层转发的配置文件夹

include /etc/nginx/tcp.d/*.conf;

请注意,stream配置不能放到http内,即不能放到/etc/nginx/conf.d/,因为stream是通过tcp层转发,而不是http转发。

如配置在http内,启动nginx会报如下错误:

nginx: [emerg] "server" directive is not allowed here

3.在tcp.d下新建个oracle.conf文件,内容如下:

stream {
upstream oracle{
server 192.168.2.3:1521;
}
server {
listen 1234;#将192.168.2.3的1521端口转发到本机的1234端口
proxy_pass oracle;
}
}

4.重启nginx,plsql访问本机的1234端口就相当于连接192.168.2.3的1521端口。

Be First to Comment

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注