I have 3 apps written in node js using the express module. Every app supports http and https. I created that for three different ports. I want to run all apps in a single pc with single IP but different domains. I have a linux server. Also, I heard nginx may be able to do it. I want like following example
Localhost:3000 -> www.domain.com
Localhost:3001 ->subdomain.domain.com
Localhost:3002 -> www.anotherdomain.com
How can i do it with it in the linux environment? Please guide me using suitable examples.
2
Answers
Assuming you’ve already installed Nginx (apt install Nginx).
Just create a separate virtual host file per each server.
For example, it can be like this for http://www.domain.com
and like this for subdomain.domain.com
I’m avoiding such things as SSL, root file, etc as this can be found elsewhere.
https://hackprogramming.com/how-to-setup-subdomain-or-host-multiple-domains-using-nginx-in-linux-server/
Don’t forget to test nginx
sudo nginx -t
and restart it to pick up changes (sudo service nginx restart
)/etc/nginx/
When you use domains to visit your page, the configuration above may help you.
Whats more you should specify one server as your default server when you visit with ip address.