Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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

 
discard

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.