Asterisk load balancing behind Nginx

Hello, thank you in advanced
here is my scenario.
i have two asterisk servers with Webrtc enabled and centralized backend MariaDB, which are load balanced behind an nginx server.
from webphone to nginx i am using LetsEncrypt SSL and then its proxied to my two asterisk servers (Round Robin), from nginx to asterisk servers i am using self signed SSL,
my extensions are added in DataBase, so when i refresh browser, extensions may get registered on any asterisk servers.
server A: 172.20.0.33
server B: 172.20.0.34

calling from one extension to another using its URI, if both are registered on the same server, calls are going thru.
but if extensions are registered on different servers, the call will not go thru.
i have monitored it and i guess problems are:

  1. URI: the URI format is sip:hkv0svst@172.20.0.59:47918;transport=ws;x-ast-orig-host=192.0.2.162:0 (172.20.0.59 is my nginx local ip address which proxies to asterisk servers)

  2. extension 100 is registered on 172.20.0.33 and extension 200 is registered on server 172.20.0.34. so calling from 100 to 200 using its URI, i see the call is sent to 200@172.20.0.33 which is the wrong asterisk IP address and result is :
    Everyone is busy/congested at this time

Please advice as i have been struggling with it for the last 5 days

Simple load balancing is not enough in this case as SIP is not stateless. I think using a SIP proxy like Kamailio plus a central place to keep your SIP accounts and registrations should do what you want.

hello thank you for your time, so you mean this is not a good senario? i tried kamailio but very few documents on it and too complicated,
another senario i wanted to try was load balancing two kamailio sip proxy servers with a virtual IP with multiple asterisk backend, does this work?
do i register my sip trunks on kamailio and pass it to asterisk?
since kamailio does sip registration handling, and i can use RTPengine for media and call recordings, why i need asterisk then? plus i tried kamailio, you can make calls and media is fine, but on document it says it doent do media streaming

Well, there is a good package that does media streaming with Kamailio. Kamailio actually has very good documentation :). It depends on whether you need Asterisk features whether Asterisk makes sense in your scenario.