I have a SaaS application wherein users can enter their domain names. The application uses the hostname of incoming requests to determine the account based on the domain they entered for their account, loading up settings, themes, etc.
I don't want to have to add a new Nginx host for each new domain that's added by a user, which leads me to a solution wherein I have all the people point their www
CNAME to a static subdomain on my server (e.g. all-websites.[my domain].com
), redirecting each root request to its respective www
version (e.g. example.com
redirects to www.example.com
).
Will the aforementioned solution work, and if so, are there any drawbacks, and if not, do you know of a better solution which still doesn't require me to update Nginx configs every time a user signs up (I also don't want to have a script editing configs for me).
Mark the
server
section you want to use as the default using thelisten
directive, so that nginx uses that if there are no matchingserver_names
. It sounds like you're always proxying to an application and that application knows how to handle the different hosts, but if necessary you can use the$host
variable in your nginx configuration.