-
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.
-
-
Save simplesoft-duongdt3/080796cb8cc33079611a6c892dfe00b0 to your computer and use it in GitHub Desktop.
Dynamically map subdomains to different ports on the server - using Nginx
This file contains hidden or 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