Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Created July 6, 2023 03:32
Show Gist options
  • Save gilangvperdana/62eeb5e9ce74f8f3ea3471024e62b7e9 to your computer and use it in GitHub Desktop.
Save gilangvperdana/62eeb5e9ce74f8f3ea3471024e62b7e9 to your computer and use it in GitHub Desktop.
Dynamic Wildcard Server Name on Nginx Block
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