Nginx配置udp/tcp四层代理

一、添加stream模块

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

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

在nginx.conf内添加stream模块(与http同一层级,一个是四层,一个是七层配置),日志格式与http不同
stream {
log_format proxy 'remoteaddr[remote_addr [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” “upstreambytesreceived""upstream_bytes_received" "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; # 配置四层日志格式
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章