Using HAproxy to forward rtmp?


#1

I want to try HAproxy to forward incoming rtmp to LXD containers. Most all tutorials and examples are
for load balancing. I am not trying to do load balancing.

So say I have an Ubuntu server with HAproxy installed.

I also have a couple of containers on the same server. I want to be able to
forward the incoming rtmp to a specific container.
The incoming rtmp would come from OBS for instance using this format: rtmp://“server IP”:1935/Container1
or Container2, etc.

On the server end, HAproxy would route the incoming rtmp to Container1. This is not exactly load balancing.
You can consider each container is owned by a specific user for the purpose of live streaming.

Any recommendations how to configure HAproxy to handle this?

Thanks,

Ray


#2

Does this config make sense?

LPCX = containers named LPC1 through 4 I’m only using 1 container at this time.

frontend rtmp-in
bind *:1935
acl url_LPCX path_beg -i /LPC1/
use_backend LPC1-backend if url_LPC1
#use_backend LPC2-backend if url_LPC2
#use_backend LPC3-backend if url_LPC3
#use_backend LPC4-backend if url_LPC4
default_backend

backend LPC1-backend
server 10.28.172.115:1935 check
#backend LPC2-backend
#backend LPC3-backend
#backend LPC4-backend


#3

Based on the previous config I posted: So the log is giving me this error:

Jun 23 17:01:37 LPC-HAproxy haproxy[4292]: [ALERT] 173/170137 (4292) : parsing [/etc/haproxy/haproxy.cfg:42] : error detected while parsing switching rule : no such ACL : ‘url_LPC1’.
Jun 23 17:01:37 LPC-HAproxy haproxy[4292]: [ALERT] 173/170137 (4292) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
Jun 23 17:01:37 LPC-HAproxy haproxy[4292]: [ALERT] 173/170137 (4292) : Fatal errors found in configuration.

Any idea why?


#4

Hi
Replace this line
use_backend LPC1-backend if url_LPC1
with
use_backend LPC1-backend if url_LPCX

or change your acl name


#5

Thanks Arash. That fixed starting HAproxy. However I am getting an error when when I send rtmp to the server. Here is the config file:

ray@LPC-HAproxy:/etc/haproxy$ cat haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon

    # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

    # Default ciphers to use on SSL-enabled listening sockets.
    # For more information, see ciphers(1SSL). This list is from:
    #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
    # An alternative list with additional directives can be obtained from
    #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
    ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
    ssl-default-bind-options no-sslv3

defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

frontend rtmp-in
bind *:1935
acl url_LPCX path_beg -i /LPC1/
use_backend LPC1-backend if url_LPCX
acl url_LPCX path_beg -i /LPC2/
use_backend LPC2-backend if url_LPCX

    #use_backend LPC2-backend if url_LPC2
    #use_backend LPC3-backend if url_LPC3
    #use_backend LPC4-backend if url_LPC4
    default_backend LPC1-backend

backend LPC1-backend
server 10.28.172.115:1935 check
backend LPC2-backend
server 10.28.172.116:1935 check

Here is the haproxy restart:

Jun 24 10:41:37 LPC-HAproxy haproxy[6239]: [WARNING] 174/103720 (6239) : Exiting Master process…
Jun 24 10:41:37 LPC-HAproxy haproxy[6239]: [ALERT] 174/103720 (6239) : Current worker 6243 exited with code 143
Jun 24 10:41:37 LPC-HAproxy haproxy[6239]: [WARNING] 174/103720 (6239) : All workers exited. Exiting… (143)
Jun 24 10:41:38 LPC-HAproxy haproxy[6271]: Proxy rtmp-in started.
Jun 24 10:41:38 LPC-HAproxy haproxy[6271]: Proxy rtmp-in started.
Jun 24 10:41:38 LPC-HAproxy haproxy[6271]: Proxy LPC1-backend started.
Jun 24 10:41:38 LPC-HAproxy haproxy[6271]: Proxy LPC1-backend started.
Jun 24 10:41:38 LPC-HAproxy haproxy[6271]: Proxy LPC2-backend started.
Jun 24 10:41:38 LPC-HAproxy haproxy[6271]: Proxy LPC2-backend started.

And when I send rtmp, here is the failure:
Jun 24 10:31:31 LPC-HAproxy haproxy[6153]: 192.168.0.5:54741 [24/Jun/2018:10:31:31.844] rtmp-in rtmp-in/ -1/-1/-1/-1/0 400 188 - - PR-- 1/1/0/0/0 0/0 “”

Ideas?

Ray


#6

Oh I am sending rtmp from OBS using this: rtmp://“haproxy server IP”:1935