Second domain on same droplet NOT working with NginX

Posted August 2, 2014 4.8k views

I’m trying to use my NginX to host multiple websites on the same droplet.
I can access and with or without the use of default_server tag. However, accessing just presents the contents of (the server block with the default_server tag) without forwarding the url to 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
I’ve created 2 DNS entries: 1 for and the other for Both have the same A and CNAME records.

@      A
www    CNAME  @
*      CNAME  @

My configs are:

Any clues?

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.

Submit an Answer
3 answers

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

Configuration servername and servername must be separated.

On your pastebin, you must remove servername first and make a second configuration for the servername

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

sudo nano /etc/hosts       localhost.localdomain   localhost

# 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
by Etel Sverdlov
This tutorial shows you how to set up virtual hosts. Virtual Hosts are used to run more than one website or domain off of a single server and IP address. When used with nginx, virtual hosts are called Server Blocks. This tutorial covers setting up server blocks on a Centos server.
  • As an addition to @iko’s answer (thank you by the way), don’t forget to clear the cache in your browser once you have made the change, as sometimes it will look like it hasn’t worked.

    edited by asb

Thanks for replying. The problem was that I only had 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.