Welcome! Log In Create A New Profile

Advanced

Websites can get to the correct server blocks

Posted by joequah1 
Websites can get to the correct server blocks
April 30, 2013 03:48AM
http://stackoverflow.com/questions/16264412/nginx-host-multiple-websites-cant-get-the-correct-website

I would like to know how to host multiple websites on a single IP address.

I'm using Nginx in Ubuntu server 12.10

I created two websites named joequah, joeproject and test in both
/etc/nginx/sites-avaliable
/etc/nginx/sites-enabled

Setting for /etc/nginx/sites-enabled/joeproject
server {
listen 80;
root /usr/share/nginx/www/joeproject;
index index.html index.htm index.php;

server_name www.joeproject.free joeproject.free;
.
.
.
}

Settings for /etc/nginx/sites-enabled/test
server {
listen 80;
root /usr/share/nginx/www/test;
index index.html index.htm index.php;

server_name test;
.
.
.
}

Settings for /etc/nginx/sites-enabled/joequah
server {
listen 80;
root /usr/share/nginx/www/joequah;
index index.html index.htm index.php;

server_name www.joequah.free joequah.free;
.
.
.
}

I have 2 domains
www.joequah.free
www.joeproject.free

I provided the same IP address to both domain. IP address only, no nameserver. I don't know what is nameserver.

Both domains will always show the SAME content.

And they won't show the same content everytime.

What I mean is joequah.free and joeproject.free will show the content of joequah now.

But later both will show content of joeproject or maybe test.

They will show content randomly, but both always showing the same content at the same time.

How to make them show the correct content? Did I configure wrongly?

Please help thanks



Edited 1 time(s). Last edit at 04/30/2013 03:52AM by joequah1.
Re: Websites can get to the correct server blocks
May 06, 2013 08:25AM
Hi,

It should work as expected. Please check two things:

1) make sure you're connecting using HTTP/1.1 protocol and not HTTP/1.0 which does not support virtual hosts.

2) in your example on stackoverflow the "listen" directive was configured ambiguously -- you must not use colon after "listen":

listen 80; # not listen: 80

3) if the above doesn't work, create a default server block:

server {
listen 80 default_server;
server_name "_";
...
}

restart nginx and see if all your requests now go to the default server. If that is the case, it means that your virtual hosts do not capture requests and that the problem lies somewhere else. Maybe HTTP/1.1 "Host:" header line is filtered out before your virtual hosts are accessed?

Andrejs
loco (at) andrews.lv
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 345
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready