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; # 配置四層日誌格式
}

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