#!/bin/bash # This script expects a mapping of services and ports in the SERVICES env var, # with one line per service containing "NAME PORT". generate_location() { # generate_location PATH URL echo -e "\t\tlocation $1 { proxy_pass $2; }" } LOCATIONS=$( echo "$SERVICES" | while read name port; do # restreamer is the catch-all [ "$name" == "restreamer" ] && generate_location / "http://restreamer:$port" # thrimshim takes any calls to thrimshim/ [ "$name" == "thrimshim" ] && generate_location /thrimshim "http://thrimshim:$port" # thrimbletrimmer takes any calls to thrimbletrimmer/; serves content from /etc/nginx/html/thrimbletrimmer; requests to the plain URL get redirect to the dashboard page. [ "$name" == "thrimbletrimmer" ] && echo -e "\t\tlocation = / { return 301 \$scheme://\$host/thrimbletrimmer/dashboard.html; }\n\t\tlocation /thrimbletrimmer { }" # all services have metrics under /metrics/SERVICE, except for thrimebletrimmer [ "$name" != "thrimbletrimmer" ] && generate_location "/metrics/$name" "http://$name:$port/metrics" done ) cat > /etc/nginx/nginx.conf <