3 ms·
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". Essentiall
by RossM 11y ago
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.
- wvenable 11y agoI'm concerned about adding ngnix to the system as that's a fairly significant change to a working system. There are a lot of variables and sites involved. I've considered reverse-proxying entirely within Apache to avoid adding ngnix another layer. But this really hinders some of the advantages of node which makes me wonder if it's worth even doing. It seems like node is best when it can handle the requests directly. Your advice here is pretty much the most common answer.
- Killswitch 11y ago> It seems like node is best when it can handle the requests directly What makes you believe that?
- wvenable 11y agoNode's single process event-loop model of handling requests seems in direct contrast to apache's one heavy-weight process/thread per request model.