This example nginx configuration will enable subdomain routing to a single backend path based on the subdomain.
It shows both catch-all routing and specific subdomain routing.
| #!/bin/bash | |
| # use host networking to enable forward to another port on localhost | |
| docker run -v $PWD/nginx.conf:/etc/nginx/nginx.conf:ro --network=host nginx |
| events { | |
| worker_connections 512; | |
| } | |
| http { | |
| server { | |
| # route any subdomain to localhost/subdomain | |
| listen 8080; | |
| server_name ~^(?<name>\w+)\.example\.com$; | |
| location / { | |
| proxy_pass http://127.0.0.1:8081/$name; | |
| } | |
| } | |
| server { | |
| # route app3 subdomain to localhost/app3-specific | |
| listen 8080; | |
| server_name app3.example.com; | |
| location / { | |
| proxy_pass http://127.0.0.1:8081/app3-specific; | |
| } | |
| } | |
| } |