Skip to content

Instantly share code, notes, and snippets.

@technolo-g
Last active April 6, 2018 22:31
Show Gist options
  • Save technolo-g/631c2c0ab5e594058133 to your computer and use it in GitHub Desktop.
Save technolo-g/631c2c0ab5e594058133 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