Question

Second domain on same droplet NOT working with NginX

  • Posted on August 2, 2014
  • sim4bizAsked by sim4biz

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: http://pastebin.com/tVMSatBJ

Any clues?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Read it first: Virtual Host Nginx: Ubuntu or Virtual Host Nginx: CentOS And do the same with the next domain.

Configuration server_name www.domain.com and server_name www.domain2.com must be separated.

On your pastebin, you must remove server_name www.domain2.com first and make a second configuration for the server_name www.domain2.com.

And add your second/next domain on your hosts. Then edit /etc/hosts. Make it look like this:

sudo nano /etc/hosts

127.0.0.1       localhost.localdomain   localhost
192.168.0.100   test.domain.com
192.168.0.100   www.domain2.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

This comment has been deleted

Thanks for replying. The problem was that I only had www.domain2.com in server_name in the site vhost but I was trying to access it without www. I now added the extra server block with return directive to take care of non-www.