mirror of https://github.com/ekimekim/wubloader
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.
73 lines
2.0 KiB
Bash
73 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
# This script expects a mapping of services and ports in the SERVICES env var,
|
|
# with one line per service containing "NAME PORT".
|
|
|
|
# Other vars:
|
|
# THRIMBLETRIMMER: Set non-empty to also serve thrimbletrimmer on /thrimbletrimmer
|
|
# BUSCRIBE: Set non-empty to also serve buscribe on /buscribe
|
|
# SEGMENTS: Set to path to segments dir to also serve segments dir on /segments
|
|
# SSL: Set to path to file containing SSL cert and key, if any.
|
|
|
|
generate_location() {
|
|
# generate_location PATH URL
|
|
# We indirect via a variable to prevent nginx from caching dns forever
|
|
echo -e "\t\tlocation $1 { set \$name \"$2\"; proxy_pass \$name; }"
|
|
}
|
|
|
|
LOCATIONS=$(
|
|
[ -n "$SERVICES" ] && echo "$SERVICES" | while read name port; do
|
|
# restreamer is the catch-all
|
|
[ "$name" == "restreamer" ] && generate_location / "http://restreamer:$port"
|
|
# thrimshim and buscribe-api take any calls to SERVICE/
|
|
if [ "$name" == "thrimshim" ] || [ "$name" == "buscribe_api" ]; then
|
|
generate_location "/$name" "http://$name:$port"
|
|
fi
|
|
# all services have metrics under /metrics/SERVICE, except for thrimebletrimmer
|
|
generate_location "/metrics/$name" "http://$name:$port/metrics"
|
|
done
|
|
[ -n "$THRIMBLETRIMMER" ] &&
|
|
echo -e "\t\tlocation = / { return 301 /thrimbletrimmer/; }" &&
|
|
echo -e "\t\tlocation /thrimbletrimmer { }"
|
|
[ -n "$BUSCRIBE" ] &&
|
|
echo -e "\t\tlocation /buscribe { }"
|
|
[ -n "$SEGMENTS" ] &&
|
|
echo -e "\t\tlocation /segments/ { alias $SEGMENTS/; }"
|
|
)
|
|
|
|
[ -n "$SSL" ] && SSL_CONF=$(cat <<EOF
|
|
server {
|
|
listen 443 ssl;
|
|
ssl_certificate $SSL;
|
|
ssl_certificate_key $SSL;
|
|
ssl_session_cache shared:SSL:10m;
|
|
gzip on;
|
|
gzip_comp_level 9;
|
|
absolute_redirect off;
|
|
$LOCATIONS
|
|
}
|
|
EOF
|
|
)
|
|
|
|
cat > /etc/nginx/nginx.conf <<EOF
|
|
worker_processes auto;
|
|
|
|
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/mime.types;
|
|
resolver 127.0.0.11 valid=10s;
|
|
client_max_body_size 20M;
|
|
$SSL_CONF
|
|
server {
|
|
listen 80;
|
|
gzip on;
|
|
gzip_comp_level 9;
|
|
absolute_redirect off;
|
|
$LOCATIONS
|
|
}
|
|
}
|
|
EOF
|