Nginx配置udp/tcp四层代理

Nginx配置udp/tcp四层代理

  • 一、添加stream模块
  • 二、配置stream模块和日志格式
  • 三、示例之添加DNS四层代理配置

一、添加stream模块

nginx编译添加stream模块,参考:http://www.cnblogs.com/crysmile/p/9565048.html

二、配置stream模块和日志格式

在nginx.conf内添加stream模块(与http同一层级,一个是四层,一个是七层配置),日志格式与http不同
stream {
log_format proxy ' r e m o t e a d d r [ remote_addr [ remoteaddr[time_local] ’
‘$protocol $status $bytes_sent KaTeX parse error: Double superscript at position 35: … '̲session_time “KaTeX parse error: Double superscript at position 35: … '̲"upstream_bytes_sent” “ u p s t r e a m b y t e s r e c e i v e d " " upstream_bytes_received" " upstreambytesreceived""upstream_connect_time”’;
include /etc/nginx/conf.d/*.stream;
}

三、示例之添加DNS四层代理配置

DNS服务走的是udp协议,dnsmasq.stream配置查看
cat conf.d/dnsmasq.stream
upstream dns {
server IP:5353;
}
server {
listen 53 udp;
proxy_responses 1;
proxy_timeout 20s;
proxy_pass dns;
error_log /var/log/nginx/dns.log;
#access_log /var/log/nginx/dns.log proxy; # 配置四层日志格式
}

你可能感兴趣的:(Nginx,反向代理)