1

It's my first day with Nginx, I found code samples that do not work for me.

This is my conf file:

upstream myapp {
    server 127.0.0.1:3000;
    keepalive 8;
}

# the nginx server instance
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name weally.org www.weally.org;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name weally.org www.weally.org;
    ssl_certificate     /etc/letsencrypt/live/weally.org/cert.pem;
    ssl_certificate_key /etc/letsencrypt/live/weally.org/privkey.pem;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;    access_log /var/log/nginx/weally.org.log;
    # add Strict-Transport-Security to prevent man in the middle attacks
    add_header Strict-Transport-Security "max-age=31536000" always;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://myapp/;
      proxy_redirect off;
    }
 }

if gives me this log:

root@ns3072230:~# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2019-08-14 08:08:56 UTC; 10s ago
     Docs: man:nginx(8)
  Process: 3901 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 1578 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 3902 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 1579 (code=exited, status=0/SUCCESS)

Aug 14 08:08:56 ns3072230 systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 14 08:08:56 ns3072230 nginx[3902]: nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/default:22
Aug 14 08:08:56 ns3072230 nginx[3902]: nginx: configuration file /etc/nginx/nginx.conf test failed
Aug 14 08:08:56 ns3072230 systemd[1]: nginx.service: Control process exited, code=exited status=1
Aug 14 08:08:56 ns3072230 systemd[1]: nginx.service: Failed with result 'exit-code'.
Aug 14 08:08:56 ns3072230 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
root@ns3072230:~# sudo vim /etc/nginx/conf.d/weally.org.conf 

I'm surprized since I saw many examples on the web with many server{} confs.

Thanks for your help

  • 1
    You have multiple configs for default_serverThe error message is quite obvious. Either disable the default site, or change your server directives. I assume you have default_server set in /etc/nginx/sites-enabled/default and in /etc/nginx/conf.d/weally.org.conf – Lenniey Aug 14 at 8:36
  • Ok thanks, removing the default_server solves the issue. It's obvious for you but for me who still doesn't know the concepts, when I did not see default_server on the second declaration, I thought it is not duplicate. I'll have to learn it a little more and recruit some specialized persons for that, for now the project has no budget :) – Zied Hamdi Aug 14 at 9:57
  • OK, glad I could help. I'll add it as an answer, too. – Lenniey Aug 14 at 10:09
0

From comment:

You have multiple configs for default_server. Either disable the default site, or change your server directives. I assume you have default_server set in /etc/nginx/sites-enabled/default and in /etc/nginx/conf.d/weally.org.conf, so nginx detects a duplicate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.