3

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).

orokusaki
  • 2,693
  • 4
  • 28
  • 42

1 Answers1

2

Mark the server section you want to use as the default using the listen directive, so that nginx uses that if there are no matching server_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.

listen 80 default_server;
mgorven
  • 30,036
  • 7
  • 76
  • 121
  • Thanks. Can that handle multiple domains or just multiple subdomaina? – orokusaki Apr 21 '12 at 11:11
  • The default `server` section will be used to handle all HTTP requests which don't match a `server_name`, so yes, this will work for any arbitrary domains. – mgorven Apr 22 '12 at 03:31