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?
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!
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
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.
This comment has been deleted
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.