Name based virtual hosts not working

Hi!

I just did a lemp setup but I can’t get my virtual hosts to work
properly.
I´m totally lost and out of ideas.
Two domains and one starting on e is always responding showing its root
and
the other starting on s is just dead. I understand that nginx is
handling
this as Apache analyzing the headers for a match and if no match it goes
alphabetically taking the first as default domain.

I have my configuration files in /etc/nginx/conf.d, domain1.conf and
domain2.conf and the root pointing to /var/www/domain1/html and
/var/www/domain2/html
The domains are pointed A records to my public IP

What can be wrong here? So many people having this problem but I can´t
find
a solution. I hope this forum are holding cutting edge professionals to
help
me out.

config file

server {
listen 80;

root /var/www/domain1/html;
index index.php index.html index.htm;

server_name domain1.com www.domain1.com;

location / {
        try_files $uri $uri/ /index.php;
}

location ~ \.php$ {
        try_files $uri =404;
        fastcgi_param SCRIPT_FILENAME

$document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}

/zzyber

Posted at Nginx Forum:
https://forum.nginx.org/read.php?2,265259,265259#msg-265259

Can you try

listen IP:80;

instead of

listen 80;

where IP is the IP address both domains resolve to ( and I assume its
the
same IP).

Hey.

I am using a setup with a bunch of domains - where I am just using the
server_name property.

As far as I can see, your config looks ok. But you have to keep in mind
one thing: the “default” property, AND if it is being accessed through a
proxy. That can - I am no expert! - possibly be a cause.

So in general, first delete - or change - the sites-enabled/default
file. Remove the “default” keyword in the “listen” entry. Why? Well, it
tends to cause NGINX to prefer one domain over another, and afaik,
having multiple of these can even lead to an error, or unexpected
behavior. Then, create files for your domains in the sites-available
folder, and symlink them to sites-enabled. I wish there was a tool for
that honestly… But first creating your configs in sites-available gives
you a listing of all the sites you could offer. Again, check for the
default keyword. Then symlink them - with their full path, not relative!

  • into sites-enabled.

You should end up with - for example - two files:

sites-enabled/domain1.com
sites-enabled/domain2.com

The both files should start similarily. Like so:

server {
listen 80;
server_name domain1.com www.domain2.com

… other stuff …

}

Just that the file for domain2.com obviously has a different
server_name.

NGINX has a handy tool to check your config. I strongly recommend doing
so before restarting. Because a full-blown reconfiguration is better
applied by a restart, thats at least how it went for me.

If your config is good, restart the service - and try again! :slight_smile:

Kind regards,
Ingwie.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs