Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. redirects to

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

share|improve this question
up vote 2 down vote accepted

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;
share|improve this answer
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 3:31
Excellent, thanks! – orokusaki Apr 22 '12 at 12:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.