Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaboesquivel/9ab673963fd61b8d2bd06cd366f6690e to your computer and use it in GitHub Desktop.
Save gaboesquivel/9ab673963fd61b8d2bd06cd366f6690e to your computer and use it in GitHub Desktop.
Redirect subdomain to port (nginx)
# This will redirect a numerical subdomain to a port.
# A use would be Docker contianers.
# This relies on the following DNS record:
# *.test.domain.com IN A 10.100.199.31
# and the fact that this container would run on the same Docker
# host as the backends.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# This captures the subdomain (if digits) as the $backport variable
server_name ~^(?P<backport>[0-9]+)\.test\.domain\.com$;
location / {
if ($backport) {
resolver 8.8.8.8;
proxy_pass http://$server_name:$backport;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment