0

I'm trying to display my NodeJS application when the user type a specific domain. I already pointed the domain on the server, then I've installed Nginx and I have created a configuration file into:

/etc/nginx/conf.d/myapp.conf

this have the following content:

server {
        listen 80;
        server_name myapp.it www.myapp.it;

        location / {
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Host $http_host;
                proxy_pass http://localhost:4568;
        }
}

I restarted Nginx and I executed this command: nginx -t but I got:

nginx: [warn] conflicting server name "myapp.it" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.myapp.it" on 0.0.0.0:80, ignored

when I visit the domain I get 403 Forbidden, that's because Letsencrypt cannot register a certificate for the conflict above. What I did wrong?

sfarzoso
  • 103
  • 4
  • Use `nginx -T` (uppercase `T`) to view the entire configuration across all included files and identify where the conflicting `server_name` is coming from. Has your editor left a backup file in the `conf.d` directory perhaps. – Richard Smith Oct 17 '20 at 16:40

1 Answers1

1

You should put the site config files in /etc/nginx/sites-enabled.

To solve your problem, check if you have a default site config in /etc/nginx/sites-enabled and delete it. Then, move your myapp.conf file to /etc/nginx/sites-enabled and restart nginx.

Jesús Ángel
  • 518
  • 2
  • 6
  • You're right! What if I have multiple node js app? Should I create a new conf each time? – sfarzoso Oct 17 '20 at 17:22
  • 1
    I don't know very much about node js apps. If each of them listens in different ports then you could add multiple locations entries in the site config, each with a different port. You sure can also add a new site config file for each app. It's up to you. – Jesús Ángel Oct 17 '20 at 17:32