You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kitsune 9f7eaeb771
1 year ago
.. feat(nginx): directly proxy spwn 1 year ago feat(nginx): build with custom openssl 1 year ago misc 1 year ago
restream.conf feat: restream server setup script 1 year ago feat(nginx): fix build and run scripts 1 year ago

nginx caching reverse proxy config

This is a good-enough example configuration for a caching reverse proxy for HLS live streams.

See it in action

# Download and compile a local version of nginx
$ ./

# Run the example configuration
$ ./

Once running, check out http://localhost:8080. By The example config proxies to, so you should see a blank player page. Feel free to check out the restream.conf file and tune it to your liking.

The build script doesn't litter your system with random junk. When you're done you can just wipe the ./nginx folder.

Reverse proxying from existing nginx

If you don't wanna bother merging the config, you can just use your existing nginx to reverse-proxy to this one. It'd look something like this:

         your server
         |                                |
viewer --|--> main nginx --> this nginx --|--> upstream
         |      w/ SSL                    |

You can just do something like this:

location / {

Merging with your existing nginx

If you want to merge it with an existing nginx config, you can copy these directives to the http block:

  • resolver and resolver_timeout (if you plan on using a domain name for the upstream)
  • proxy_cache_path
  • upstream

And then you can copy the server block in too. If you want to merge it with an existing server, you can just copy all the proxy_ directives. Note that it'll add caching to the whole server by default, so if you don't want that, you can change proxy_cache to off, and then in the location blocks where you do the reverse proxy, set proxy_cache back to restream_cache.

Feel free to tweak the parameters to fit your needs, but generally the values in restream.conf should just work alright for caching live streams.

Setting this up on a remote server

The convenience script can be used to ssh into a fresh remote server, install nginx there, configure the upstream and set up SSL. This should work on a fresh Ubuntu 20.04 server.

Run the script:

./ \
  --domain \
  --upstream-server \
  --acme-email \

Important note: you must specify the protocol (https://) and the port (:443) for the --upstream-server flag.

Once the script is done, your server should be accessible from and proxying all requests to

Example 2: setting up a relay for SPWN:

./ \
    --domain \
    --upstream-server '' \
    --upstream-base '/spwn-archives/xxxxx/xxxx' \
    --acme-email \
    --target-server \
    --pass-header User-Agent '[user agent string]' \
    --pass-header Cookie '[redacted]' \
    --pass-header Referrer ''


  • --upstream-server: Include the https:// in front and the :443 port number, and do not include a trailing /.
  • --upstream-base: The rest of the URL before the index.m3u8 file. Start with a / but do not add a / at the end.