Node/Express respond only to specific domains - node.js

Is it possible to bind different hostnames to different Express instances?
For example: example.com would direct to one NodeJs/Express instance running on port 80 and example.org would direct to another NodeJs/Express instance running on port 80.
If this is completely confusing, think of how IIS is capable of binding specific host headers to specific IIS websites.

Related

routing subdomains to a specific port in nodejs

I have two react frontend servers (example1 and example2) listening on two ports on MyDomain.com:
MyDomain.com:4000 accesses example1
MyDomain.com:5000 accesses example2
I have two subdomains, example1.MyDomain.com example2.MyDomain.com
I want to create a third nodejs server that will listen on port say 3000 and route requests to ports 4000 and 5000 depending on the subdomain accessed.
example1.MyDomain.com will be routed to MyDomain.com:4000
and
example2.MyDomain.com will be routed to MyDomain.com:5000
could not find an example that addresses port numbers except for ngnix
I also tried using proxy middleware but the examples show how to route according to the suffix after the .com and that is not what I need.
Thanks for any help,
Amnon
I highly recommend you to use one of the popular proxies/load balancers for that Nginx, HAProxy, Envoy, Traefik.
If you want to do it specifically with node.js you will need create proxy server on your own,but that is not a good idea because the apps mention above already have that functionality and they are built specifically for that use case

Docker: Multiple container on port 80 without NGinx

I want to run multiple web server on the same VM. Each web server is dockerized.
Is it possible to run multiple dockerized web servers on port 80, with different domains, using docker functionalities?
I found many solution based on NGinx proxy like here , but I don't find any user defined network usage that solves this problem.
Is there any solution to this problem without running a reverse proxy?
No.
There is only one "real" port 80 on the host server (for each network address), so you need something that listens there and forwards to the different backend servers.
This is not a docker-specific problem. You cannot run multiple (non-Docker) web servers (one for each domain) on a single port either.
That something does not have to be nginx.
As far as I am aware, no it can not work to have multiple containers listening on port 80 or the same port in general.
You could open up different ports on your VM and have the applications listening to each one of those ports specifically.
For instance you could have your first application listen to port 80. Then your second one on port 81, etc.
First of all it is possible to run multiple domains on the same port, but the requirement is that:
you host sites on the same web server (Apache HTTPD or Nginx)
you are using virtual hosts
The one server can be containerized, if needed.
Here is the example of running two domains on exactly one Nginx web server.
So depending on your requirements, that can be solution.

multiple nodejs apps for multiple domains on the same machine/ip. switching ports

We have multiple domains each have embedded nodejs app we need to make every nodejs app running url like : http://domain_name:port_number
but we have a strange problem that every port we set for any nodejs app could be accessed from one domain not the domain we set the port in its nodejs app except 8080
How to make all ports accessible from all domains running on the same machine/ip or open port number for a domain
we use apache as the web server not using express or nginx
The problem solved there was a dns settings on cloudeflare prevents completing requests

How to specify the port serving CherryPy app in the DNS entry?

I receive a "Port 80 not free" message when I try to serve my CherryPy app on port 80. Most examples I see show folks using other ports. If I use another port how do I specify the port serving my CherryPy app in the DNS entry?
We're using Easy DNS and from what I can tell there is no way to specify the port in the DNS entry. Is this standard or a restriction with our provider?
Want to achieve something like this:
XXX.XXX.XXX.XXX - www.domain.com:9595
Thanks in Advance!
Andrew
To publish the TCP port number for your web site in DNS, you can create an SRV record, but there is no point in doing that since there are probably exactly zero web browsers in existence that actually query SRV records to find out which port to connect to.
So since SRV doesn't work, the short answer is to your question is, you can't. If your web server runs on a different port than 80 (for HTTP) or 443 (for HTTPS) then it is only possible to access it by specifying the port number directly in the URL, like http://www.domain.com:9595/.
If you really prefer to have your web site appear to be on port 80 (for HTTP) or 443 (for HTTPS) and there is already another web server listening on that port, then you can see if you can configure the other web server to proxy requests to your web server. For example, if the other web server runs Apache, then:
<Location /foo>
ProxyPass http://localhost:9595/
ProxyPassReverse http://localhost:9595/
</Location>

deploying a node.js on a new domain

I have a server that runs different websites on different ports. All of them (but one) are Apache servers and thanks to webmin, I managed to have, for instance, example.com point to 123.123.123.123:80 and example.fr to 123.123.123.123:8000, somehow automatically
I am now running a nodejs server on the same machine, so the 80, 8000, and many other ports are already taken. My nodejs listens on 8008. I have another domain name, say example.org, and I want it to point to my nodejs website, but I simply don't know how to do that! I have updated the DNS and everything is pointing to 123.123.123.123 (my server's IP). I want to avoid using an ugly example.org:8008/ for everything on this node server. How can I make it point implicitly to the 8008 port?? I must add that I cannot afford to take down the apache servers ;)
DNS only provides name to ip address mapping. It cannot handle ports. What you can do instead is to set up a proxy server listening on port 80. The proxy server can then return data based on the host header.
Your best option is to just redirect the request from Apache. Otherwise you can use a reverse proxy like Nginx. Also, you can write a lightweight proxy in node... check out this page

Resources