Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple domains on one server points to wrong sites

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.

like image 868
Staffan Estberg Avatar asked Jan 29 '14 09:01

Staffan Estberg


People also ask

Can you have two domains pointing to the same server?

Can a single server be associated with multiple domains? Yes. This would be done by pointing those domains at your web server via DNS.

Can multiple domain names point to the same site?

Pointing two URLs to the same website is a good way to direct traffic to your site from several different domain names. You can accomplish this in two ways: either redirect one of the URLs to your primary domain, or create an alias for one of the URLs. The alias would point that domain towards your primary domain.

Can you have multiple domains linked to one website?

With most registrars, it's easy to forward multiple domains to your website so you can simply create one site and then redirect visitors who type one of your other domain names to that one website.

Does having multiple domains hurt SEO?

Having multiple domains may help or hurt SEO based on your brand(s), strategy, and investment in the process. In general, multiple domains will create SEO concerns when not executed properly, so you'll want to understand how to leverage each domain according to the overall strategy.


3 Answers

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.

like image 171
JClarke Avatar answered Nov 15 '22 12:11

JClarke


I was having the same problem with my Ubuntu/nginx/gunicorn/django 1.9 sites on my local machine. I had two nginx files in my /etc/nginx/sites-enabled. Removing either one allowed to remaining site to work. Putting both files in ended up always going to one of the two sites. I'm not sure how it chose.

So after looking at several stack overflow questions without finding a solution I went here: http://nginx.org/en/docs/http/request_processing.html

It ends up that you can have multiple servers in one sites-enabled file, so I changed to this:

server {
    listen 80;
    server_name joelgoldstick.com.local;
    error_log    /var/log/nginx/joelgoldstick.com.error.log debug;
    location / {
        proxy_pass http://127.0.0.1:8002;
    }
    location /static/ {
        autoindex on;
        alias /home/jcg/code/python/venvs/jg18/blog/collect_static/;
    }
}

server {
    listen 80;
    server_name cc-baseballstats.info.local;
    error_log    /var/log/nginx/baseballstats.info.error.log debug;
    location / {
        proxy_pass http://127.0.0.1:8001;
    }
    location /static/ {
        autoindex on;
        alias /home/jcg/code/python/venvs/baseball/baseball_stats/collect_static/;
    }
}

I can now access both of my sites locally

like image 43
joel goldstick Avatar answered Nov 15 '22 12:11

joel goldstick


Check out the /etc/nginx/sites-enabled/ directory if there is any temp file such as ~default. Delete it and problem solved.

Credit: @OmarIthawi nginx error "conflicting server name" ignored

like image 27
pbo Avatar answered Nov 15 '22 12:11

pbo