shaun
By:
shaun

NGINX Websites all point to same place

April 10, 2014 3.2k views
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:

Site 2

Working

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.
9 Answers
Try using just one server block for each domain name. So there should only be two: `server {`

`sudo service nginx restart`

http://wiki.nginx.org/ServerBlockExample
Still the same problem as before unfortunately. Here's the new one:
http://pastebin.com/ACnQ9pMv
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:
http://pastebin.com/0qpCfzkL
put a phpinfo.php in the site root.

phpinfo();
?>

Load it http://web1.com/phpinfo.php and http://web2.com/phpinfo.php
And check the DOCUMENT_ROOT variable to make sure is using the same server block.

Also remove the ";" from the server block 2

access_log /var/log/nginx/web2.com;error_log /var/log/nginx/web2.com;
It could be giving problems since ";" is the config terminator
@Shaun: What file is this? Can you pastebin /etc/nginx/nginx.conf?
It sounds as if there is a misconfig in your Server Blocks in /etc/nginx/sites-available/sites

If you could share your configs, I will definitely provide corrections:

Your server block can be configured as follows:

1. /var/www/web1/public_html

# Server Block Configuration for www.web1.com
server {
listen 80;
# listen [::]:80 default_server ipv6only=on;

root /var/www/web1/public_html;
index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name web1.com www.web1.com;

2. /var/www/web2/public_html

# Server Block Configuration for www.web2.com
server {
listen 80;
# listen [::]:80 default_server ipv6only=on;

root /var/www/web2/public_html;
index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name web2.com www.web2.com;

Best Wishes,

Geneva Sibanda
http://magwinya.co.za
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.

Here are the 3 nginx files I've modified:
- /etc/nginx/nginx.conf: Pastebin
- /etc/nginx/sites-available/web1: Pastebin
- /etc/nginx/sites-available/web2: Pastebin

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.

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.

Any ideas? I'm completely stuck.
And you add the domains to the hosts? My problem was the server name, but not your case.
Have another answer? Share your knowledge.