0

I've had a single domain on my server which was setup by someone else however i'm trying to add a 2nd domain, after following a couple of tutorials off google i'm running into some issues.

Here is my default (i didn't create this one):

server {
    listen 80 default;
    #server_name www.domain-one.net domain-one.net;
    root /var/www/html/domain-one;
    index index.php index.html;
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_read_timeout 300000;
    }
}

That config works absolutly fine, According to the tutorial i was reading i had to setup another file so i did this and created a link but when i run nginx -t i get an error

nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/default:2

This is my 2nd config file which i created:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/domain-two;
    index index.html index.htm index.php;

    server_name domain-two.info www.domain-two.info;

    location / {
        try_files $uri $uri/ =404;
    }
}

Guessing i'm doing something wrong?

3
  • You can't have two default servers on the same port.
    – AD7six
    Oct 17, 2015 at 12:48
  • So i should just remove the word default_server from the 2nd config ?
    – Exoon
    Oct 17, 2015 at 12:50
  • remove the conflicting/duplicate listen statements
    – Aaron
    Oct 17, 2015 at 16:06

1 Answer 1

3

You want to have two server blocks. Both listening to the same IP address (I presume) but with different server names. Yes, remove the default_server since you can't have two.

server {
    listen xxx.xxx.xxx.xxx:80;
    server_name mysite.com;
    root /home/mysite;
...
}

server {
    listen       xxx.xxx.xxx.xxx:80;
    server_name  mysite2.com;
    root /home/mysite2;
...
}
2
  • I did that and no longer get the error, However when i visit the domain-two.info it goes to the same page as the first domain?
    – Exoon
    Oct 17, 2015 at 12:55
  • @Exoon Make sure you have different roots set for each server.
    – Rob
    Oct 17, 2015 at 12:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .