kitsune 9f7eaeb771
2022-01-31 01:27:43 +08:00
.. feat(nginx): directly proxy spwn 2022-01-30 04:34:48 +08:00 feat(nginx): build with custom openssl 2022-01-29 21:50:45 +08:00 misc 2022-01-31 01:27:43 +08:00
restream.conf feat: restream server setup script 2022-01-30 00:34:16 +08:00 feat(nginx): fix build and run scripts 2022-01-27 21:35:30 +08:00

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.