nginx透传udp、tcp端口
-
需要nginx编译时,支持加载stream模块。
./configure --prefix=/usr/local/nginx --with-stream
-
配置stream 需要在nginx的http和events区域块之间配置即可。
user root;
worker_processes auto;
error_log logs/error.log;
pid sbin/nginx.pid;
events {
use epoll;
worker_connections 65535;
}
stream {
upstream sipserver {
server 192.168.127.2:5060 max_fails=1 fail_timeout=10s;
server 192.168.127.3:5060 max_fails=1 fail_timeout=10s backup;
}
upstream httpapi {
server 192.168.127.4:8080 max_fails=1 fail_timeout=10s;
server 192.168.127.5:8080 max_fails=1 fail_timeout=10s backup;
}
server {
listen 5060 udp reuseport;
proxy_pass sipserver;
}
server {
listen 18080;
proxy_pass httpapi;
}
}
http {
include mime.types;
default_type application/octet-stream;