Multiple domains on one server points to wrong sites

multiple-domains, nginx, server-configuration

Solution

Your `nginx.conf` loads its external server files from the path you have in your include directives.

If you have a file in `include /etc/nginx/conf.d/*.conf;` and its symlinked to `include /etc/nginx/sites-enabled` it's going to load the file twice which would cause that error.

Problem

Using Nginx, I've created a multiple domain setup for one server consisting of four individual sites. When I start Nginx I get an error message and the sites seem to get mixed up as typing in one url leads to one of the other sites. The error message displayed - ``` Restarting nginx: nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored nginx. ``` I've set up all four domains in a similar manner in their respective file under /sites-available - ``` server { listen 80; root /var/www/example.com/public_html; index index.php index.html index.htm; server_name example.com www.example.com; location / { try_files $uri $uri/ /index.html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` I've checked and there is no default file in /sites-enabled. Guessing there might be a faulty setting in the Nginx main config but not sure as to what to look for.

Original source