Asterisk servers behind nginx load balancer

Hi, thanks for asterisk community.
I create a simple voip, voice call system with asterisk and jssip
now, I used multi asterisk and an nginx server as loadbalancer, in browser client signaling is good and work properly. But no sound is transmitted, i have no idea what is wrong here.

There is insufficient information here. Do the Asterisk instances have public IP addresses? Are they behind NAT? Have you configured them to know they are behind NAT[1] and forwarded ports?

[1] https://github.com/asterisk/asterisk/blob/master/configs/samples/rtp.conf.sample#L133

1 Like

I create a simple voip, voice call system with asterisk and jssip

How simple? Can you explain the basic components in sufficient detail that we
can understand what is running where, and how the machines are network
connected to each toher?

now, I used multi asterisk

What does that mean?

and an nginx server as loadbalancer,

What, for SIP???

in browser client signaling is good and work properly. But no sound is
transmitted,

“Good signalling and no sound” is often an indication of NAT problems, but
without knowing anything about your network setup, or even what rôle nginx is
playing here, that is just a wild guess.

i have no idea what is wrong here.

Neither have we, until you tell us enough about what it is you’ve built that
we can at least understand which machines are running what software and how
they communicate with each other.

Antony.

Hi capture the network log like sngrap or other tools so you knows media or nat or any other problem

If I understand you correctly, you’re using WebRTC and websockets with Asterisk, and put Nginx in front of the Asterisk servers, for loadbalancing?

WebRTC requires more than just HTTP traffic to flow, and unless Nginx is able, and configured properly, to also handle the audio and eventual video streams in the calls, it will not pass the traffic through.

When putting a load balancer in front of your webservers, or in this case Asterisk servers running HTTP(s), it’s common to have your backend servers on private IPs or have traffic rules in place, that does not allow direct traffic between the outside world, and the backend servers.

In this case you’d want Nginx to act as a RTP proxy, this means it will have to rewrite the SDP of the voice signalling, and proxy the RTP streams. Another option is giving the Asterisk backend servers a public IP address, and allow RTP traffic to flow directly between the clients and Asterisk backend servers. You can configure Asterisk to use a certain port range for RTP, if clients are communicating with each other, or with the PSTN, you would need 2 ports per active call, if all traffic is terminating on the Asterisk server, (Eg. you play a recording then terminates the call, you record a message of some sort etc.) a single RTP port per call is sufficient. For conferences each participant will need a RTP port.

1 Like

Hi @Chano

Call me @8510967375

First of all, that phone number is written in a format I’m unfamiliar with. There’s no country code for a start.

Second, you don’t state what I should call you about, or why it can not be handled here.

Hi Chano, yes your are correct, first of all i use jssip and asterisk for make voice call from browser to a pstn number, i configure asterisk for webrtc, i create a webrtc client with username and password and use it to connect to asterisk. its work properly, then i decided to scale this system and i select nginx because i am familiar with it more than other server like kamelio or kurento. for now every thing is in local network and i will move servers on internet. signaling is very good but after i pick up the phone there is not sound. i do not use turn or stun server for this step. thanks for your help.

thanks jcolp, for first step every thing is in local network, so there is no need to public ips

also i have another question, as i know i can just have one call from each webrtc client user to a pstn number instantly, but i want to scale this system that multi clients use my asterisk and webrtc client configuration to call to pstn number instantly, do you know any solution for this? thanks in advance

Unless there’s a SIP module for Nginx, it’s the wrong tool for handling SIP traffic.

You would need a webrtc proxy/load balancer, to handle your use case. If I’m not mistaken, there’s some sort of webrtc support in kamailio, but I’m not really following their development, as I’m not the one maintaining our kamailio setup. I handle the Asterisk side of things. :wink:

But really your problem seems to be using the wrong tool for the job.

Nginx as a load balancer for websites, works like a charm, for webRTC and SIP, it’s a bit more involved, and as far as my 10 sec search goes, Nginx is not up to the job.

I’m not really understanding the service you’re trying to provide. Do you intent to setup a softphone for internal use whenever employees need to call out? Do you need to setup a web gateway for the general public, for calling your customer service? Or something completely different?

For load balancing you could have some sort of mechanism that checks the load on each of your Asterisk serveres, gathering AMI events for having a count of current calls per server would be the best solution. However, depending on the number of webclients, you can also just contact each Asterisk server, whenever a client connects to the website, and assign a server at that time.

A more simple approach could be just having your webfront select a server in a round-robin fashion, it’ll not always assign the client to the least loaded server, but it might be “good enough” in your situation, or as a start.

Also keep in mind, that Asterisk servers does NOT share state between each other, and as such you may be able to use realtime for certain aspects of the configuration, but things like registrations, current calls etc. will not be shared, making it impossible to perform internal calls between clients on different servers, without an external router, who knows where the client currently resides.

If I were you, I’d go with this plan for moving forward.

  1. Make the web and Asterisk stuff work with a single webserver and a single Asterisk server.
  2. Load balance the website, if needed.
  3. Setup Asterisk server number 2, and make it work with the webfront on it’s own.
  4. Decide on a load balancing strategy. Easy mode being letting the web application handle Asterisk server selection.

For having multiple calls running, all you need is having an agreement with your ITSP on the number of simultaneous calls you require.

thank you, i working on a system that clients (from browser, android , etc) be able to make a voice call over internet with (webrtc) to a pstn number. signaling do with asterisk, and media do with webrtc. targets is preson that have just static phone (no internet) in Pstn network. in a simple example this work good. but for scaling there is some problem like loadbalancing and etc. some person suggest to use media server and i do not how to create this architecture yet. i was decided to use nginx just for signaling load balancing but as you mention this is not good choice

What is the relation to the clients? Are they customers needing support? Are they randoms paying for phone calls? Is the destination a single static number, or multiple numbers the user can choose, or perhaps even any number in the world they desire?

You have 3 components in your solution.

  1. A softphone (The WebRTC client running in the browser on your website)
  2. A server handling the calls, Asterisk in this case.
  3. A connection to the PSTN, usually provided by a 3rd party, unless you’re a telco yourself.

The softphone has very little to do with Asterisk. It’s a web application with whatever capabilities you give it. Keep in mind, that anything running in a browser, can be controlled by the user, and as such is insecure. Any username and passwords you put in the webRTC client configuration, will be visible to the user, and they WILL be able to use these credentials to connect another webRTC client to your Asterisk server, bypassing any kind of limitations you build into the website. Therefore all security and limits in regards to numbers being called, must be done in Asterisk.

Asterisk will handle all communications between your softphone and the telco you chose for outbound calls. I have a hard time imagining exactly what solution you’re making, the technical requirements, does not say anything about what you’re trying to provide to the clients.
A solution for customers to call your customer service for free using just a web browser, is one solution, and I’d probably look at a way to dial the customer service phone system directly instead of sending calls through an ITSP, as that would also keep your costs down.

I see very few use cases for calling a single phone number from a web browser, through the PSTN, that does not have other and better solutions.

also how many users / concurent calls are you expecting

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.