2016-11-29 319 views
0

我試圖在2個不同的服務器Nginx的TCP轉發基於域名

前使用nginx的代理

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; 
} 

} 

我有檢查TCP load balance guide,但我怎麼也找不到,使其工作

回答

0

使用server_name指令,以確定哪些服務器塊用於給定的請求。

server { 
    listen 1935; 
    server_name example.com; 
    location/{ 
     proxy_pass 10.0.0.1:1936; 

     # the usual proxy_* stuff 
    } 
} 
server { 
    listen 1935; 
    server_name example1.com; 
    location/{ 
     proxy_pass 10.0.0.2:1936; 

     # the usual proxy_* stuff 
    } 
} 

來源:http://nginx.org/en/docs/http/server_names.html

+0

我已經使用這個端口80,流是rtmp,它會給重複否? – Lolak

+0

@譚宏達,糾正我,如果我錯了,但'server_name'只適用於'http'塊,而不是'stream'塊,它似乎@Lolak需要代理rtmp連接。 – Michael

0

tcp load balancing page of nginx

nginx tcp load balancing example




根據示例嘗試這個例子:

stream { 
    upstream rtmp_servers { 
    least_conn; 
    server 10.0.0.2:1935; 
    server 10.0.0.3:1935; 
    } 
} 

server { 
    listen  1935; 
    server_name example.com, example1.com; 
    proxy_pass rtmp_servers; 
} 
+0

謝謝,但沒有工作「服務器」指令在這裏是不允許的,我不能在http { – Lolak

+0

裏面添加它你能解釋一下你把這段代碼放在哪裏嗎? – num8er

+0

在nginx.conf中,我有那裏HTTP {服務器代理端口80等}然後流{code},試圖代理端口80 HTTP和端口1935 1936 rtmp – Lolak