Reputation: 1535
In my error log i get
[emerg] 10619#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/mysite.com:4
on Line 4 I have:
server_name mysite.com www.mysite.com;
Any suggestions?
Upvotes: 152
Views: 184994
Reputation: 211
OS Debian 10 + nginx. In my case, I unlinked the "default" page as:
cd /etc/nginx/sites-enabled
unlink default
service nginx restart
Upvotes: 21
Reputation: 1491
I my case, I already have a file inside the sites-enabled.
And the issue had resolved after removing the unwanted and swap related files.
Options to try the nginx configuration is ok or not by the command
sudo nginx -t
Result:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Upvotes: 1
Reputation: 370
In my case, commenting out the wildcard directive on include
in the /etc/nginx/nginx.conf
worked
#include /etc/nginx/sites-enabled/*;
include /etc/nginx/sites-enabled/abcdef.com;
PS: as per the comments above, this could be a solution if there is just one configuration (either default or your custom one)
Upvotes: 5
Reputation: 148
If davidjb's answer does not show multiple default_server lines, check for multiple include directives.
It is possible you accidentally included your default (or another site) twice.
Upvotes: 0
Reputation: 1444
In my case junk files from editor caused the problem. I had a config as below:
#...
http {
# ...
include ../sites/*;
}
In the ../sites
directory initially I had a default.config
file.
However, by mistake I saved duplicate files as default.config.save
and default.config.save.1
.
Removing them resolved the issue.
Upvotes: 2
Reputation: 1040
Execute this at the terminal to see conflicting configurations listening to the same port:
grep -R default_server /etc/nginx
Upvotes: 13
Reputation: 51
If you're on Digital Ocean this means you need to go to /etc/nginx/sites-enabled/ and then REMOVE using rm -R digitalocean and default
It fixed it for me!
Pic of Console on Windows 10 using Bitvise
Upvotes: 5
Reputation: 8727
You likely have other files (such as the default
configuration) located in /etc/nginx/sites-enabled
that needs to be removed.
This issue is caused by a repeat of the default_server
parameter supplied to one or more listen
directives in your files. You'll likely find this conflicting directive reads something similar to:
listen 80 default_server;
As the nginx core module documentation for listen
states:
The
default_server
parameter, if present, will cause the server to become the default server for the specifiedaddress:port
pair. If none of the directives have thedefault_server
parameter then the first server with theaddress:port
pair will be the default server for this pair.
This means that there must be another file or server
block defined in your configuration with default_server
set for port 80. nginx is encountering that first before your mysite.com
file so try removing or adjusting that other configuration.
If you are struggling to find where these directives and parameters are set, try a search like so:
grep -R default_server /etc/nginx
Upvotes: 285