feat(nginx): fix build and run scripts
This commit is contained in:
+24
-4
@@ -1,9 +1,29 @@
|
||||
# nginx caching reverse proxy config
|
||||
|
||||
Check the `restream.conf` file for a good-enough caching reverse proxy setup
|
||||
with nginx. It should just work with the default nginx that ships with most
|
||||
distros. It can be copied straight to `/etc/nginx/nginx.conf` and it _should_
|
||||
just work.
|
||||
This is a good-enough example configuration for a caching reverse proxy for HLS
|
||||
live streams.
|
||||
|
||||
## See it in action
|
||||
|
||||
```bash
|
||||
# Download and compile a local version of nginx
|
||||
$ ./build.sh
|
||||
|
||||
# Run the example configuration
|
||||
$ ./run.sh
|
||||
```
|
||||
|
||||
Once running, check out [http://localhost:8080](http://localhost:8080). By The
|
||||
example config proxies to `restream.dev`, 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.
|
||||
|
||||
## Merging with your existing nginx
|
||||
|
||||
If you don't wanna bother merging the config, you can just use your existing
|
||||
nginx to reverse-proxy to this one.
|
||||
|
||||
If you want to merge it with an existing nginx config, you can copy these
|
||||
directives to the `http` block:
|
||||
|
||||
@@ -2,12 +2,8 @@
|
||||
|
||||
set -e
|
||||
|
||||
tmpdir="$(mktemp -d)"
|
||||
prefix="$1"
|
||||
|
||||
if [ -z "$prefix" ]; then
|
||||
prefix="$(pwd)/nginx"
|
||||
fi
|
||||
tmpdir="$(mktemp -d -p .)"
|
||||
prefix="$(pwd)/nginx"
|
||||
|
||||
mkdir -p "$prefix"
|
||||
|
||||
|
||||
+29
-15
@@ -3,6 +3,8 @@
|
||||
worker_processes auto;
|
||||
events { worker_connections 128; }
|
||||
|
||||
error_log /dev/stderr;
|
||||
|
||||
http {
|
||||
# Basic settings
|
||||
sendfile on;
|
||||
@@ -11,17 +13,25 @@ http {
|
||||
server_tokens off;
|
||||
keepalive_timeout 300s;
|
||||
types_hash_max_size 2048;
|
||||
include ./nginx/conf/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
# Logging settings
|
||||
access_log /dev/stdout;
|
||||
|
||||
# Set DNS resolver
|
||||
resolver 1.1.1.1 8.8.8.8 valid=300s ipv6=off;
|
||||
resolver_timeout 10s;
|
||||
|
||||
# TODO: Update cache path to your cache directory
|
||||
proxy_cache_path
|
||||
/var/cache/nginx/restream
|
||||
# cache directory (e.g. /var/cache/nginx/proxy_cache)
|
||||
./cache
|
||||
use_temp_path=off
|
||||
# the name of the cache, if you change this
|
||||
# you have to update the proxy_cache directive below
|
||||
keys_zone=restream_cache:10m
|
||||
# maximum size of the cache, feel free to tune it
|
||||
max_size=20g
|
||||
inactive=10m;
|
||||
|
||||
@@ -29,18 +39,22 @@ http {
|
||||
# TODO: Add your upstream here. For HTTP-only
|
||||
# upstreams, omit the :443, and change the
|
||||
# https:// to http:// in the proxy_pass directive.
|
||||
server stream.example.com:443;
|
||||
server restream.dev:443;
|
||||
}
|
||||
|
||||
# HTTPS configuration
|
||||
# Server configuration
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
# Example SSL config
|
||||
# listen 443 ssl;
|
||||
# listen [::]:443 ssl;
|
||||
# server_name example.com;
|
||||
# ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
|
||||
# ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
|
||||
|
||||
# TODO: Add your server name here
|
||||
server_name example.com;
|
||||
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
|
||||
# Or for non-SSL
|
||||
listen 8080;
|
||||
listen [::]:8080;
|
||||
server_name _; # TODO: change with your domain name
|
||||
|
||||
proxy_redirect off;
|
||||
proxy_http_version 1.1;
|
||||
@@ -74,11 +88,11 @@ http {
|
||||
}
|
||||
|
||||
# Optional: redirect all requests to https
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name _;
|
||||
# server {
|
||||
# listen 80;
|
||||
# listen [::]:80;
|
||||
# server_name _;
|
||||
|
||||
return 307 https://$server_name$request_uri;
|
||||
}
|
||||
# return 307 https://$server_name$request_uri;
|
||||
# }
|
||||
}
|
||||
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
script_dir=$(readlink -f $(dirname $0))
|
||||
|
||||
echo "Starting nginx"
|
||||
echo "Press Ctrl+C to stop"
|
||||
mkdir -p "$script_dir/nginx/cache"
|
||||
"$script_dir/nginx/sbin/nginx" \
|
||||
-c "$script_dir/restream.conf" \
|
||||
-g "daemon off;" \
|
||||
-e /dev/stderr
|
||||
Reference in New Issue
Block a user