Nginx Different Domains on Same IP

Your “listen” directives are wrong. See this page: http://nginx.org/en/docs/http/server_names.html.

They should be

server {
    listen      80;
    server_name www.domain1.example;
    root /var/www/domain1;
}

server {
    listen       80;
    server_name www.domain2.example;
    root /var/www/domain2;
}

Note, I have only included the relevant lines. Everything else looked okay but I just deleted it for clarity. To test it you might want to try serving a text file from each server first before actually serving PHP. That’s why I left the ‘root’ directive in there.

Leave a Comment