-
You need to create an wilcard A record for the domain(or subdomain) first.
A * points to 1.2.3.4 Automatic
-
Create an nginx config file with above content & restart the web server.
-
Done.
Created
March 21, 2019 13:54
-
-
Save v1shwa/65cc0d168b29d24d09e478c9ea8e1cb7 to your computer and use it in GitHub Desktop.
Dynamically map subdomains to different ports on the server - using 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
server { | |
listen 80; | |
# maps p8080.example.com -> localhost:8080 | |
server_name ~^p(?<port>[^.]+)\.example\.com$; | |
location / { | |
proxy_pass http://localhost:$port; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment