Nginx用做sip代理

https://www.jianshu.com/p/14d134cbf8d3?tdsourcetag=s_pcqq_aiomsg

看了这篇文章的方案一,我专门试了试,记录如下:

测试环境为:

fs1(5080) --- nginx --- fs2(5060)

局域网同一个网段,fs1把呼叫送到nginx的5060,后者代理到fs2的5060

第一步,fs1和fs2默认配置,sip call flow如下:

fs1       nginx        fs2

    invite--->

                  invite--->            

                 <---200

<---200

ack------------------->

坏了,ack直接发到fs2,没有经过nginx(没有rr头, ct指向fs2)

第二步,调整fs1和fs2的配置,ext-sip-ip都指向nginx,localnet.auto deny所有

再测试,现在ack可以经过nginx,bye也正常

第三步,继续调整fs1和fs2配置,ext-rtp-ip都指向nginx,让rtp通过nginx转发,最后的结果是:

fs1                        nginx                       fs2

              sip5080<----

                                 --->sip 5060

         rtp(2000-2099) <---

                                 --->rtp(30000-30099)

结论到底如何,看官来总结吧

最后附上nginx配置文件:

#fs1:
#192.168.1.126
#sip:5080
#rtp:2000-2099

#nginx
#192.168.100.75

#fs2:
#192.168.1.12
#sip:5060
#rtp:30000-30099

user  root;
worker_processes  auto;

error_log  /var/log/nginx/error.log debug;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}

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;

    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;
}

stream {
    log_format proxy '$proxy_protocol_addr $remote_addr [$time_local] '
    '$protocol $status $bytes_sent $bytes_received '
    '$session_time "$upstream_addr" '
    '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

    server {
        listen 5060;

        access_log /var/log/nginx/tcp/5060_access.log proxy;
        error_log  /var/log/nginx/tcp/5060_error.log debug;

        proxy_timeout 5s;
        proxy_pass 192.168.1.12:5060;
    }

    server {
        listen 5060 udp reuseport;

        access_log /var/log/nginx/udp/5060_access.log proxy;
        error_log  /var/log/nginx/udp/5060_error.log debug;

        proxy_timeout 5s;
        proxy_pass 192.168.1.12:5060;
    }
	
	# rtp to 192.168.1.12:30000-30099/udp
    server {
        listen 30000-30099 udp reuseport;

        access_log /var/log/nginx/udp/30000-30099_access.log proxy;
        error_log  /var/log/nginx/udp/30000-30099_error.log debug;

        proxy_timeout 5s;
        proxy_responses 1;
		proxy_pass 192.168.1.12:$server_port;
    }

	# sip to 192.168.1.126:5080/tcp
    server {
        listen 5080;

        access_log /var/log/nginx/tcp/5080_access.log proxy;
        error_log  /var/log/nginx/tcp/5080_error.log debug;

        proxy_timeout 5s;
        proxy_pass 192.168.1.126:5080;
    }
	
	# sip to 192.168.1.126:5080/udp
    server {
        listen 5080 udp reuseport;

        access_log /var/log/nginx/udp/5080_access.log proxy;
        error_log  /var/log/nginx/udp/5080_error.log debug;

        proxy_timeout 5s;
        proxy_pass 192.168.1.126:5080;
    }
	
	# rtp to 192.168.1.126:2000-2099/udp
    server {
        listen 2000-2099 udp reuseport;

        access_log /var/log/nginx/udp/2000-3000_access.log proxy;
        error_log  /var/log/nginx/udp/2000-3000_error.log debug;

        proxy_timeout 5s;
        proxy_responses 1;
		proxy_pass 192.168.1.126:$server_port;
    }
}

你可能感兴趣的:(nginx,服务器)