Skip to content

Instantly share code, notes, and snippets.

@simplesoft-duongdt3
Forked from v1shwa/dynamic_subdomains
Created May 24, 2023 09:43
Show Gist options
  • Select an option

  • Save simplesoft-duongdt3/080796cb8cc33079611a6c892dfe00b0 to your computer and use it in GitHub Desktop.

Select an option

Save simplesoft-duongdt3/080796cb8cc33079611a6c892dfe00b0 to your computer and use it in GitHub Desktop.

Revisions

  1. @v1shwa v1shwa created this gist Mar 21, 2019.
    14 changes: 14 additions & 0 deletions dynamic_subdomains
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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;
    }
    }
    7 changes: 7 additions & 0 deletions instructions.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    - 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.