Expose the server in a subfolder
HTTP-based services (Media-over-QUIC, WebRTC, HLS, Control API, Playback Server, Metrics, pprof) can be exposed in a subfolder of an external HTTP server or reverse proxy. The reverse proxy must be able to intercept HTTP requests addressed to MediaMTX and corresponding responses, and must perform the following changes:
The subfolder path must be stripped from request paths. For instance, if the server is exposed behind
/subpathand the reverse proxy receives a request with path/subpath/mystream/index.m3u8, this has to be changed into/mystream/index.m3u8.Any
Locationheader in responses must be prefixed with the subfolder path. For instance, if the server is exposed behind/subpathand the server sends a response withLocation: /mystream/index.m3u8, this has to be changed intoLocation: /subfolder/mystream/index.m3u8.
Nginx
When Nginx is the reverse proxy, rules described above can be implemented with the following configuration:
location /subpath/ {
proxy_pass http://mediamtx-ip:8889/;
proxy_redirect / /subpath/;
}Apache HTTP Server
When Apache HTTP Server is the reverse proxy, rules described above can be implemented with the following configuration:
<Location /subpath>
ProxyPass http://mediamtx-ip:8889
ProxyPassReverse http://mediamtx-ip:8889
Header edit Location ^(.*)$ "/subpath$1"
</Location>Caddy
When Caddy is the reverse proxy, rules described above can be implemented with the following configuration:
:80 {
handle_path /subpath/* {
reverse_proxy {
to mediamtx-ip:8889
header_down Location ^/ /subpath/
}
}
}