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

I'm trying to host multiple domains (with simple static pages) on a single VPS, running Ubuntu 12.04 LTS, nginx. The basic nginx configs for all domains are similar to this one (all separated in sites-available dir) :

server { 
 listen 80; 
 server_name www.example.com; 
 return 301 $scheme://example.com$request_uri; 
}

server { 
 listen 80; 
 server_name example.com;

 root /home/username/example.com; 
 index index.html; 
}

it works for first domain, for second domain it works only if I removed the first server block, for third domain it doesn't work at all. nginx fails to start. I don't what I'm doing wrong.

share|improve this question
    
You'll need to actually post the configuration which is giving you trouble. –  Michael Hampton May 28 '13 at 17:11
    
I just found the solution, in the nginx error log it was saying "could not build the server_names_hash, you should increase server_names_hash_bucket_size: 64". I think it was due to the longer domain names. –  rkjha May 28 '13 at 17:36

4 Answers 4

up vote 2 down vote accepted

The problems was the lengthy domain names. When I checked the nginx error log, I found this error message:

could not build the server_names_hash, 
you should increase server_names_hash_bucket_size: 64

So, I un-commented the following line in /etc/nginx/nginx.conf file.

http {
 ....
 #server_names_hash_bucket_size 64;
 ....
}

Now, everything works as expected :)

share|improve this answer
    
Holy crap, I had the same problem. Thanks! The limit in default nginx seems to be 14 characters per domain, which seems ridiculously short. –  Kevin Chen May 1 '14 at 4:17

If you want to test your sub-domains on localhost you may have to add the name of it to your local hosts file. normally localted in /etc/hosts

Somehow those sub domains have to be resolved, try adding sub.localhost 127.0.0.1, and if your going to the web add an A record with your server ip, and check the DNS with

dig www.myexample.com

it should come back with an IP if its working, and do the same with each sub domain.

Let me know if this works

share|improve this answer
    
I don't think it's a DNS issue here, nginx fails to start - so that's where the problem lies. BTW, I've tested that by editing my /etc/hosts file - it works fine when the server is running. –  rkjha May 28 '13 at 16:17
1  
Does Nginx give you any sort of error when restarting or does it just start a new command line without any feedback? –  Nukra May 28 '13 at 16:19
    
no, i don't get any error. It doesn't start or restart(if already running) silently. –  rkjha May 28 '13 at 16:21
    
thats usually because you have a syntax error in your config, please check this for multiple domains; pastebin.com/nFxHhFjb This usses sub domains but the template is easily adapted for more domains –  Nukra May 28 '13 at 16:26
    
syntax error ? where exactly, can you please clarify that. –  rkjha May 28 '13 at 16:30

Change the "return 301" to "rewrite..."

server { 
 listen 80; 
 server_name www.example.com; 
 rewrite ^(.*)$ $scheme://example.com$request_uri; 
}
share|improve this answer

If you need to run multiple domain names (using cloud hosting services) there is a step-by-step tutorial which shows how easily it is to configure multiple domains with Jelastic.

share|improve this answer
    
Welcome to Server Fault! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  slm Aug 22 '13 at 12:56

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.