Skip to content

Instantly share code, notes, and snippets.

@keyboardcrunch
Created November 22, 2024 03:53
Show Gist options
  • Save keyboardcrunch/f5fd782306aeff0ee124fc3e9822655a to your computer and use it in GitHub Desktop.
Save keyboardcrunch/f5fd782306aeff0ee124fc3e9822655a to your computer and use it in GitHub Desktop.
Nginx wildcard subdomain, map and upstream example
# Setup an "upstream" to allow preferences between local or tailscale endpoints for an Ollama service
# Note: I'm running a similar config on my laptop so I can access services while local or remote but
# use upstream to pick the endpoint to use.
upstream chat {
ip_hash;
server 192.168.1.3:11434;
server 100.44.39.165:11434;
}
# Setup a map to associate our proxy endpoint with the subdomain
map $subdomain $prxy {
video http://192.168.1.6:8080;
chat http://chat; # This is our upstream reference
}
server {
# Match on the subdomain for our website.net domain
server_name ~^(?<subdomain>\w+)\.website\.net$;
# Proxy subdomain matches and include url paramaters
location / {
proxy_pass $prxy;
include proxy_params;
}
}
@keyboardcrunch
Copy link
Author

Still need to do a few things to clean up formatting, handle errors better, and ensure letsencrypt/certbot compatibility.

  • add and validate a "default" value to the map or redirect if not $prxy
  • validate existing server_name works with LE/Certbot, if not move to *.primary.com and extract subdomain differently
  • dockerize this with hot reload on conf changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment