i need to put my node js application on server, it's actually two applications :

February 6, 2018 220 views
Nginx Ubuntu

i need to put my node js application on server, it's actually two applications :

app1(frontend) on VM-link:3000, when the user writes the message it calls the app2 (Backend) on VM-link:3001 or VM-link:3001/socket.io/

So i used a nginx proxy to relate these two virtual machines in my www.domain.com and i wanted them to run on domain.com/chatbot

my nginx config file :

server {
  listen [::]:80;
  server_name domain.com;

  access_log  /var/log/nginx/permit_access.log;
  error_log   /var/log/nginx/permit_error.log;

location /chatbot {
   proxy_pass         http://VM-link:3000;
   proxy_redirect     off;

    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

# Websockets support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; }

location /back {
   proxy_pass         http://VM-link:3001;
   proxy_redirect     off;

    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

# Websockets support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /socket.io {
    proxy_pass         http://VM-Link:3001/socket.io/;
    proxy_redirect     off;

   proxy_set_header   Host             $host;
   proxy_set_header   X-Real-IP        $remote_addr;
   proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}
} 

Problem : when i write domain.com/chatbot and i write a message it calls domain.com:3001

Question : how can i fix this without touching the code (i mean using the config file)

Be the first one to answer this question.