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?

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

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy