Question

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.

No correct solution

OTHER TIPS

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.

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

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

In my case no sites-enabled nor double includes ....

The solution was avoiding more than one reference (if you consider all of the conf.d files as a whole) to "listen 80" and "server_name" references ...

In my case, default.conf and kibana.conf both included references to this guys ... I commented the one in default and problem solved !

My 2 cents ....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top