I have a created new Nginx server which I am using for reverse proxy for my 2 NodeJS apps.
- First app I need to run on example.com
- 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;
}
}