nginx代理tcp协议转发实例
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
stream {
include /etc/nginx/tcp.d/*.conf;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
[root@yn-srv-qyapp tcp.d]# more rt-rrdw40000.conf
upstream rtrrdw {
hash $remote_addr consistent;
server 10.25.*.*:40000 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 40000;
proxy_pass rtrrdw;
proxy_connect_timeout 10s;
proxy_timeout 24h;
}
[root@yn-srv-qyapp tcp.d]#
注意:默认编译的时候该模块并未编译进去,需要编译的时候添加--with-stream
,使其支持stream代理。
检查方法:nginx -V
https://zhuanlan.zhihu.com/p/69164457