Nginx TCP forwarding based on domain name

Lolak picture Lolak · Nov 29, 2016 · Viewed 32.2k times · Source

i am trying to use nginx proxy in front of 2 different servers

example.com , example1.com >> nginx 10.0.0.1 >>>> 10.0.0.2 , 10.0.0.3

 stream {


server {
 listen 1935;
    proxy_pass 10.0.0.2:1936;
          proxy_protocol on;
}
server {
 listen 1935;
    proxy_pass 10.0.0.3:1936;
          proxy_protocol on;
}

}

i have check the tcp load balance guide but i could not find how to make it work

Answer

aloisio picture aloisio · Jun 29, 2017

Although there is no server_name in TCP/UDP protocol, you can forward the traffic to different upstream based on $server_addr. My example is here: https://stackoverflow.com/a/44821204/5085270