nginx vhost error "duplicate default server"
This was a total brain fart on my part. To begin with I tried to start nginx like so:
sudo systemctl start nginx.service
when it failed I checked for an error message:
sudo systemctl status -l nginx.service
Then, after I had fixed the problem I looked to see if the error was still present by running sudo systemctl status -l nginx.service
again, but without attempting to start the service, that command just gives me the last error! Therefore I was getting the same error despite having already fixed the problem. Remember folks, when changing nginx config, you have to actually start the service before you check for an error message.
Related videos on Youtube
![Frank Conry](https://i.stack.imgur.com/BMKC8.png?s=256&g=1)
Frank Conry
Updated on September 18, 2022Comments
-
Frank Conry almost 2 years
I have a problem settingup name based vhosts on a CentOS 7 box I have set up. When I try to start up, I get the following error:
Dec 07 20:55:28 li805-37 nginx[7284]: nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/conf.d/website-one.conf:2
Here is the contents of
/etc/nginx/nginx.conf
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; }
and the vhost configs, first
website-one
which runs node:upstream node_server { server 127.0.0.1:3000 fail_timeout=0; } server { listen 80; server_name website-one.com; index index.html index.htm; access_log /var/log/webone/access.log; error_log /var/log/webone/error.log debug; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_redirect off; proxy_buffering off; proxy_pass http://node_server; } location /public/ { root /opt/website-one; } }
then
website-two
which is a static html site for now:server { listen 80; server_name website-two.com; access_log /var/log/webtwo/access.log; error_log /var/log/webtwo/error.log debug; index index.php index.html index.htm; location / { root /var/www/; } }
Also I have tried greping for "default_server" in the
/etc/nginx
directory and the result just hit two commented out lines in/etc/nginx/nginx.con
that I have removed for brevity.-
Michael Hampton over 7 yearsThe config files you've pasted don't correspond to the error message. Please check everything and make any necessary corrections to your question.
-
Frank Conry over 7 yearsI'm sure I'm missing something, but those are all the config files and the error message specifically mentions the config I have pasted in. Is there something else that I'm not including tha tI should be?
-
Michael Hampton over 7 yearsI don't know what you haven't included. That's why I asked you to check that you've actually pasted the actual files.
-
Tim over 7 yearsGrep for "default_server". You have two of them, you can only have one (that's the short beginners version of the answer, it's not 100% correct).
-
Frank Conry over 7 yearsI did grep default_server the only lines that come up are commented out nginx config none are in any of the conf files in the conf.d
-
Ginnungagap over 7 yearsThe pasted configuration, beyond having missing elements doesn't seem coherent with what NGINX says. Your first server should have the listening directive on line 2 when it's on line 6 so the pasted configuration doesn't match the one NGINX is loading. Moreover, you list your nginx.conf like it's in
/etc/nginx/conf.d
which I imagine it isn't. -
Frank Conry over 7 years@Ginnungagap you're right the path was wrong, I've corrected that now its should be
/etc/nginx/nginx.conf
and the example server config is from the "configuring nginx" section of this site: terlici.com/2015/04/20/hosting-deploying-nodejs-centos.html -
Frank Conry over 7 yearsSo I figured it out. I was not restarting the server correctly, in fact I was just checking the status over and over
sudo systemctl status -l nginx.service
after I correctly modified the config. Sorry for the wild goose chase. -
dim-0 over 7 yearsWould you mind creating a separate answer with your findings and mark it as the solution then? This way the question will show up as answered. Thank you.
-