Assume I have three different sites running. Node.js app on port 3000, Apache/PHP on port 80, and then a Go app on port 5000.
How can I have three different domain names that go to each port?
I was thinking of a basic route system on port 80 that all domains refer to, then the program looks at url and redirects to correct port. Is that recommended? Is there a better way?
Thanks
If you're already using Nginx, you can very easily set up named-based reverse proxy vhosts for the apps that aren't on port 80:
server {
listen *:80;
server_name nodeapp.mydomain.com;
location / {
proxy_pass http://localhost:3000;
}
}
server {
listen *:80;
server_name goapp.mydomain.com;
location / {
proxy_pass http://localhost:5000;
}
}
If what you're running on port 80 is just a proxy layer, you could instead use caddy, which is itself written in Go. Your Caddyfile would like something like this:
nodeapp.mydomain.com {
proxy / localhost:3000
}
goapp.mydomain.com {
proxy / localhost:5000
}
If not, you could still use caddy and just move your PHP application to a different port.
I suggest caddy because its creator pushes for security everywhere (you will notice you get automatic https if your site is applicable). The configuration (done in the Caddyfile) is also usually short and very easy to understand. Caddy has a wide range of use cases and can come with plugins to do just about anything you can think up.