Question

NGINX Websites all point to same place

  • Posted April 10, 2014

I followed this tutorial: https://www.digitalocean.com/community/articles/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3

I have two websites: web1 and web2 and their respective directories on the droplet are:

  1. /var/www/web1/public_html
  2. /var/www/web2/public_html

In my sites-available directory I have a file called ‘sites’. The contents of the file is here: http://pastebin.com/0yz3Lrwt

I have two files in the /etc/nginx/global directory: common.conf and wordpress.conf. - The contents of each is: Common.conf: http://pastebin.com/gZxPeNBt Wordpress.conf: http://pastebin.com/UdA9JrZr

I created a symbolic link from sites-available to sites-enabled and I have checked inside the sites-enabled directory and the only link in there is the one for the ‘sites’ file.

In the public_html directory for web2, I have index.html containing the following HTML: <html><body><h1>Site 2</h1><p>Working</p></html>

The problem is that when I go to both web1.com and web2.com it comes up with the following text: “Site 2 Working”. It seems like web1 and web2 are both pointing to /var/www/web2/public_html, when web1 should be pointing to /var/www/web1/public_html

Anyone have any ideas? I’ve been stuck on this for a couple of days and can’t work out how to get past it.

Subscribe
Share

This comment has been deleted


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

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.

And you add the domains to the hosts? My problem was the server name, but not your case.

Any ideas anyone?

I tried what you guys have said but to no avail. I reinstalled nginx and have redone the configs to something much simpler than before. I’ve also split each site into a separate file to make things simpler. <br> <br>Here are the 3 nginx files I’ve modified: <br>- /etc/nginx/nginx.conf: <a href=“http://pastebin.com/nZ8FBrEP”>Pastebin</a> <br>- /etc/nginx/sites-available/web1: <a href=“http://pastebin.com/qAUsUFU3”>Pastebin</a> <br>- /etc/nginx/sites-available/web2: <a href=“http://pastebin.com/EUR2auis”>Pastebin</a> <br> <br>I’ve created the soft symbolic links for web1 and web2, pointing to the /etc/nginx/sites-enabled directory. I also deleted the default one in sites-enabled. <br> <br>With these configs, I still have the same problem as before with web1.co, web2.co.uk and the IP address of the droplet all pointing to the index.html file inside the web1 directory. Preferably, the IP of the droplet would go nowhere and the two domains would point to the correct directories. <br> <br>Any ideas? I’m completely stuck.

It sounds as if there is a misconfig in your Server Blocks in /etc/nginx/sites-available/sites <br> <br>If you could share your configs, I will definitely provide corrections: <br> <br>Your server block can be configured as follows: <br> <br>1. /var/www/web1/public_html <br> <br># Server Block Configuration for www.web1.com <br>server { <br> listen 80; <br># listen [::]:80 default_server ipv6only=on; <br> <br> root /var/www/web1/public_html; <br> index index.php index.html index.htm; <br> <br> # Make site accessible from http://localhost/ <br> server_name web1.com www.web1.com; <br> <br>2. /var/www/web2/public_html <br> <br># Server Block Configuration for www.web2.com <br>server { <br> listen 80; <br># listen [::]:80 default_server ipv6only=on; <br> <br> root /var/www/web2/public_html; <br> index index.php index.html index.htm; <br> <br> # Make site accessible from http://localhost/ <br> server_name web2.com www.web2.com; <br> <br>Best Wishes, <br> <br>Geneva Sibanda <br>http://magwinya.co.za

@Shaun: What file is <a href=“http://pastebin.com/0qpCfzkL”>this</a>? Can you pastebin <code>/etc/nginx/nginx.conf</code>?

put a phpinfo.php in the site root. <br> <br><?php <br>phpinfo(); <br>?> <br> <br>Load it http://web1.com/phpinfo.php and http://web2.com/phpinfo.php <br>And check the DOCUMENT_ROOT variable to make sure is using the same server block. <br> <br>Also remove the “;” from the server block 2 <br> <br>access_log /var/log/nginx/web2.com;<—.access.log; <br>error_log /var/log/nginx/web2.com;<—.error.log; <br> <br>It could be giving problems since “;” is the config terminator

Follow what was written on the NGINX wiki page you posted, I’ve now shortened the ‘sites’ file a bit, but I still have the same problem: <br>http://pastebin.com/0qpCfzkL

Still the same problem as before unfortunately. Here’s the new one: <br>http://pastebin.com/ACnQ9pMv

Try using just one server block for each domain name. So there should only be two: server { <br> <br>sudo service nginx restart <br> <br>http://wiki.nginx.org/ServerBlockExample