0

In my DigitalOcean droplet, I'm trying to use my NginX to host multiple websites on the same droplet. I can access test.domain1.com and domain1.com with or without the use of default_server tag. However, accessing domain2.com just presents the contents of domain1.com (the server block with the default_server tag) without forwarding the url to domain1.com in the browser. I've checked for typo in my configs but can't find one. Secondly, neither the access.log nor the error.log have any issues.

The hostname of my droplet is domain1.com. I've created 2 DNS entries: 1 for domain1.com and the other for domain2.com. Both have the same A and CNAME records.

@ A ip.add.re.ss www CNAME @ * CNAME @

My configs are:
/etc/nginx/nginx.conf:
http://pastebin.com/AWf5EM66
/etc/nginx/global/wordpress.conf:
http://pastebin.com/Uc9KSqhh
/etc/nginx/global/restrictions.conf:
http://pastebin.com/cLfMv6jC

/etc/nginx/sites-available/sites.conf:

server {
    listen 80;
    listen [::]:80;

    root /usr/share/nginx/html/domain1_test;
    index index.php index.html index.htm;

    server_name test.domain1.com;

    include global/restrictions.conf;
    include global/wordpress.conf;

}

server {
    listen 80;
    listen [::]:80;

    root /usr/share/nginx/html/domain2.com;
    index index.php index.html index.htm;

    server_name www.domain2.com;

    include global/restrictions.conf;
    include global/wordpress.conf;
}

server {
    listen 80 default_server;
    listen [::]:80;

    root /usr/share/nginx/html/domain1.com;
    index index.php index.html index.htm;

    server_name www.domain1.com;

    include global/restrictions.conf;
    include global/wordpress.conf;
}

Any clues?

  • I'm guessing you have only www.domain2.com in server_name in the site vhost but you are trying to access it without www ? – Florin Asăvoaie Aug 2 '14 at 20:58
  • Yes, this seemed to be the problem. I now added the extra server block with return directive to take care of www. – Shah Ismail Aug 3 '14 at 16:13
  • Added an answer with this so it can be documented well. – Florin Asăvoaie Aug 4 '14 at 6:27
1

This is because you do not have a server with the domain2.com as server_name, only www.domain2.com. Either add domain2.com as server_name to the same server as www.domain2.com, either create another server for domain2.com that redirects to www.domain2.com using return.

Your Answer

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

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