Using HLS behind Nginx reverse proxy in Docker containers #3408
Replies: 2 comments
-
Try adding a trailing slash: I found this config works for me for WebRTC:
Without trailing slashes I had issues. |
Beta Was this translation helpful? Give feedback.
-
Hello, basically you want to proxy the HLS server but you also want to add a prefix to all paths. The configuration posted by @RyanEwen works perfectly if you add a final slash to all your URLs (example: http://localhost/webcam/camera1.stream/). The only thing that is not covered is when you want to use URLs without final slashes (example: http://localhost/webcam/camera1.stream), since the server will reply with a 301, pointing to the path with the slash. You can intercept and fix these requests this by adding a dedicated block inside Nginx:
|
Beta Was this translation helpful? Give feedback.
-
Question
Hi, I'm using Mediamtx in a Docker container on a Windows system.
I publish an RTSP feed (called camera1.stream) to Mediamtx and read HLS from Mediamtx and display in a browser using the built-in HLS player.
This all works perfectly if I open port 8888 on the Mediamtx docker container like this in the docker-compose.yml:
mediamtx:
build: ./mediamtx
ports:
- 8888:8888
In a browser, I go to http://localhost:8888/camera1.stream and the stream plays perfectly.
However, I have problems when trying to put Mediamtx behind an Nginx reverse proxy running in another container on a shared Docker bridge network. The steps I take are:
mediamtx:
build: ./mediamtx
# ports:
# - 8888:8888
upstream mediamtx {
server mediamtx:8888;
}
server {
listen 80 default_server;
server_name localhost;
root /usr/share/nginx/html;
}
So I expect to navigate to http://localhost/webcam/camera1.stream to see the player but this does not work.
In the browser network log, the series of requests are:
http://localhost/webcam/camera1.stream GET 301 Moved Permanently
http://camera1.stream/ GET 307 Temporary Redirect
https://camera1.stream/ [Fails]
So the browser is being redirected to http://camera1.stream/ and https://camera1.stream/ which cannot be served by Nginx.
Any idea what I'm doing wrong or is there any documentation or examples of how to setup Mediamtx HLS behind a reverse proxy using Docker containers?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions