0

Im using NGINX for http proxy like below

http {
server {
    server_name  example.com;

    location / {
        proxy_pass http://localhost:3000/;
    }
}
}

I would like to know anyway to use NGINX for RTMP something like

rtmp {
    server {
        server_name  example.com;
        location / {
            proxy_pass rtmp://localhost:1935;
        }
    }
}
vy.pham
  • 571
  • 6
  • 20

2 Answers2

2

I have looked at Nginx documentation, below configuration can be useful. Nginx TCP and UDP Load Balancing

stream {
    server {
        listen            3000;
        proxy_pass        localhost:1935;
        proxy_buffer_size 32k;
    }
}
Ismail Durmaz
  • 2,521
  • 1
  • 6
  • 19
  • For those getting an error on the 'stream' directive, this feature appears to be "NGINX Plus" only. – Don Park Dec 11 '21 at 19:19
  • @DonPark Could you please point to the documentation that says it's only available in "NGINX Plus"? I was able to use it with the --with-stream configuration parameter. https://nginx.org/en/docs/stream/ngx_stream_core_module.html – Deep Dec 20 '21 at 13:17
  • Upon closer inspection of the TCP Load balancing page linked above the prereq shows "Latest NGINX Plus or latest NGINX Open Source built with the --with-stream configuration flag". I was getting an error from the stream directive which I took to mean its an NGINX+ feature but its more likely my nginx wasnt built with the stream module. – Don Park Dec 21 '21 at 17:40
0

@ismaildurmaz's answer was just about what I needed, but in my case I also wanted RTMPS (ie: RTMP over TLS). This was accomplished with:

stream {
  server {
    listen            1935 ssl;
    proxy_pass        127.0.0.1:1936;
    proxy_buffer_size 32k; 

    ssl_certificate     /path/to/ssl.crt;
    ssl_certificate_key /path/to/ssl.key;
  }
}

Here, the upstream RTMP server is configured to listen on port 1936, since nginx listens to port 1935 on all interfaces.

Lemon Cat
  • 1,002
  • 11
  • 14