Created
July 6, 2023 03:32
-
-
Save gilangvperdana/62eeb5e9ce74f8f3ea3471024e62b7e9 to your computer and use it in GitHub Desktop.
Dynamic Wildcard Server Name on Nginx Block
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; | |
server_name ~^([\w-]+)\.YOURDOMAIN\.com$; | |
return 301 https://$host$request_uri; | |
} | |
server { | |
listen 443 ssl; | |
server_name ~^([\w-]+)\.YOURDOMAIN\.com$; | |
ssl_certificate /etc/letsencrypt/live/YOURDOMAIN.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/YOURDOMAIN.com/privkey.pem; | |
location / { | |
proxy_pass https://YOURBACKENDSERVER; | |
proxy_set_header host $host; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment