Name based virtual hosts not working
Kevin "Ingwie Phoenix" Ingwersen
ingwie2000 at googlemail.com
Sat Mar 12 16:59:50 UTC 2016
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! :)
Kind regards,
Ingwie.
> Am 12.03.2016 um 06:40 schrieb zzyber <nginx-forum at forum.nginx.org>:
>
> 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
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
More information about the nginx
mailing list