It's a fairly common scenario. We're doing this with nginxbut docker'll be a good solution soon enough. The terms to search for are "reverse proxy".
Essentially you setup nginx to listen on port 80, Apache to listen on another port (say, 8080) and node to listen on a different port (say, 8081). Then have your nginx config differentiate between the two:
upstream apache {
server 127.0.0.1:8080;
}
upstream nodeapp {
server 127.0.0.1:8081;
}
server {
listen 80;
server_name myphpapp.example.com;
location / {
proxy_pass http://apache;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name mynodeapp.example.com;
location / {
proxy_pass http://nodeapp;
proxy_set_header Host $host;
}
}
IMO this gets a little easier to think about if you substitute your Apache -(mod_php)-> PHP setup for Nginx -(fastcgi)-> php-fpm - handing off to an appserver rather than a webserver.