Last active
April 6, 2018 22:31
-
-
Save technolo-g/631c2c0ab5e594058133 to your computer and use it in GitHub Desktop.
Redirect subdomain to port (nginx)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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