Score:-1

Nginx Reverse Proxy working on wrong server_name (Sub domain ignored)

br flag

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;
        }

}
Nikita Kipriyanov avatar
za flag
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?
Aayush avatar
br flag
@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.
ws flag
Re second question: One question per post please / We don't know how you want your stack to behave.
ws flag
"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.
Aayush avatar
br flag
@symcbean Updated the question to reflect all the queries.
Aayush avatar
br flag
@symcbean basically my server_name is being ignored, instead of the subdomain endpoint.example.com, the app is running on example.com?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.