-1

I have a created new Nginx server which I am using for reverse proxy for my 2 NodeJS apps.

  1. First app I need to run on example.com
  2. Second app I need to run on endpoint.example.com

I created the file endpoint.example.com in sites-available as follows, enabled it and nothing worked (default "Welcome to nginx page kept showing"). As soon as I remove the default file from sites-enabled, my endpoint app started working on example.com instead of the subdomain endpoint.example.com

My Nginx version is nginx/1.18.0 (Ubuntu)

I haven't even reached the second app and therefore, my sites-enabled folder has only one file which is endpoint.example.com

I don't understand what is happening, server_name is being ignored.

server {
    listen 80;

    server_name endpoint.example.com;

    root /var/www/html/endpoint;
    index index.html index.htm;

    location / {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

The default file (No longer active, deleted from sites-enabled):

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }

}
Aayush
  • 97
  • 4
  • Remove `default` symlink, e.g. the object `/etc/nginx/sites-available/default` or what else did you mean by that? Also, in general we need to see not only this snippet, but the full Nginx configuration, or at least parts you added or changed yourself; can you please attach it into the question as well? – Nikita Kipriyanov Aug 15 '23 at 05:28
  • @NikitaKipriyanov Yes I removed the default file from the sites-enabled. It's an absolutely brand new server so I have changed absolutely nothing except for adding this file. – Aayush Aug 15 '23 at 06:56
  • Re second question: One question per post please / We don't know how you want your stack to behave. – symcbean Aug 15 '23 at 08:38
  • 1
    "nothing worked" is not a menaingful diagnosis. You've not provided your default configuration nor the names of the files in sites-enabled. You've not told which version of nginx this is. – symcbean Aug 15 '23 at 08:39
  • @symcbean Updated the question to reflect all the queries. – Aayush Aug 15 '23 at 09:12
  • @symcbean basically my server_name is being ignored, instead of the subdomain endpoint.example.com, the app is running on example.com? – Aayush Aug 15 '23 at 09:19

0 Answers0