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 am new to Nginx, switched 2 days ago from Apache.

With Apache my website had 1 main url (www.example.com & example.com) and 2 subdomains (s1.example.com & s2.example.com).

I succeeded to configure Nginx to work with PHP but I have 1 major problem:

In the config file, inside a server block I've set

server_name example.com www.example.com

Underneath it, in another server block, I've set (With a different root)

server_name s1.example.com s2.example.com

Also, I have all example.com, www.example.com, s1.example.com and s2.example.com pointed to localhost IP in /etc/hosts file (and the domain CNAMEs for www, s1 & s2 are all set to example.com).

The problem is that every url I access to giving me the same as example.com. All the URLs mentioned gives me the same page (index.html in example.com).

Are there a something wrong in my config file?

share|improve this question

migrated from webmasters.stackexchange.com Mar 20 at 12:18

This question came from our site for pro webmasters.

    
Can you provide the full config for your Web Sites ? –  krisFR Mar 20 at 12:38

1 Answer 1

Not sure how you have setup your Virual Hosts because you should have provided more of your config file.

However something like this should work :

server {
   listen  80;
   index   index.html index.htm;
}

server {
   server_name example.com www.example.com;
   root /var/www/domain1;
}

server {
   server_name s1.example.com s2.example.com;
   root /var/www/domain2;
}
share|improve this answer

Your Answer

 
discard

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