174
server {
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    #root /usr/share/nginx/www;

root /home/ubuntu/node-login;
    # Make site accessible from 
    server_name ec2-xx-xx-xxx-xxx.us-west-1.compute.amazonaws.com;

location /{
    proxy_pass http://127.0.0.1:8000/;
    proxy_redirect off;
}
}

this results in nignx error [warn] conflicting server name "ec2..." on 0.0.0.0:80 ignored I dont understand, any explanation appreciated. Thanks.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
user1447121
  • 2,861
  • 4
  • 22
  • 23
  • 1
    There seems to be an implicit default 0.0.0.0:80, adding it explicitly worked for me. listen ec2-xx-xx-xxx-xxx.us-west-1.compute.amazonaws.com:80; followed by the server_name directive worked. – user1447121 Jul 11 '12 at 17:24
  • 1
    Check `/etc/nginx/sites-available/` that is linked to `/etc/nginx/sites-enabled/`. Additional files here may contain duplicate or conflicting configuration. – Hanxue Dec 23 '15 at 10:36
  • 1
    changing `config.force_ssl = true` to `false` solved my problem, this took me days to figure out – Ibukun Muyide Jul 06 '18 at 02:02
  • 4
    For me this same error was from a missing semi-colon at the end of one of the `server_name` lines when I had several `server` entries. – Kevin May 24 '19 at 12:04
  • 3
    Certbot from LetsEncrypt had added a server block in the default file in my case. It did that cause I tried to get the certificate before I had setup the separate server block. – Alex D Oct 25 '19 at 17:46
  • In my case I had [multiple](https://stackoverflow.com/a/51480365/2195238) `server` block in one file. After I separated them to ist own config files warnings were gone. – Jasom Dotnet Dec 27 '20 at 08:47
  • 1
    @Kevin THANKS. A nasty semi-colon was missing. – Firmino Changani Mar 13 '21 at 20:54
  • If you are missing the `listen` directive it can cause the same error to show. – Obay Abd-Algader Jun 01 '22 at 08:36
  • I dumbly got this error when omitting the semi-colon at the end of the server_name line. – Paul Apr 18 '23 at 17:53

3 Answers3

215

I assume that you're running a Linux, and you're using gEdit to edit your files. In the /etc/nginx/sites-enabled, it may have left a temp file e.g. default~ (watch the ~).

Depending on your editor, the file could be named .save or something like it. Just run $ ls -lah to see which files are unintended to be there and remove them (Thanks @Tisch for this).

Delete this file, and it will solve your problem.

Community
  • 1
  • 1
Omar Al-Ithawi
  • 4,988
  • 5
  • 36
  • 47
41

You have another server_name ec2-xx-xx-xxx-xxx.us-west-1.compute.amazonaws.com somewhere in the config.

VBart
  • 14,714
  • 4
  • 45
  • 49
  • 2
    I checked for that and didn't find any. it does not give this warning when i remove the "ec2_xxx ...". Is there an implicit default for 0.0.0.0:80 in nginx config ? – user1447121 Jul 11 '12 at 17:06
  • 1
    [Official documentation](http://nginx.org/r/listen): `default: listen *:80 | *:8000;` – VBart Oct 08 '12 at 20:06
  • 2
    This was it for me, however it was `localhost`. – tim-phillips Nov 20 '14 at 19:22
  • @VBart your link gave me a hint, actually my browser was prefixing https instead of http in my url, thanks – Nikhil Bhardwaj Jan 06 '22 at 08:23
  • 1
    I used: cd /etc/nginx/sites-available; grep -rnw . -e domain.com – Alex Jan 08 '23 at 21:44
  • In my case certbot added duplicate configuration into default configuration file. just remove the configuration from default config file located at /etc/nginx/conf.d/default.conf: – Roman M Jul 30 '23 at 19:23
23

There should be only one localhost defined, check sites-enabled or nginx.conf.

Marin
  • 12,531
  • 17
  • 56
  • 80
  • 12
    I had two identical "server_name" directives in two separate *.conf files. Thanks. – Felipe Alvarez Apr 05 '16 at 04:24
  • 3
    This solved my issue as well. I had placed 2 same server blocks in different *.conf files. Thanks! – Pranav Jituri May 11 '17 at 10:25
  • 2
    Also, check all files in this directory: `/etc/nginx/conf.d`. Each domain can appear only once (as a `servername` value) amongst files in that directory, as well. That was my issue! – SherylHohman Nov 13 '18 at 22:24