简体   繁体   中英

Running Node and Apache Side by Side

I am working on a project which allows users to monitor energy consumption. The main dashboard page is a web app which is pretty neat and makes extensive use of javascript and ajax. The server currently runs apache and uses php; however, I am planning on installing node.js and updating the server side scripts in order to support websockets (and I also like the idea of using javascript on the server and client side).

I have followed several online introductions but I am struggling to find answers to specific questions which I need to get my head round before I can start, one of which is outlined below.

The server is currently running CentOS, would it be better to install Ubuntu server instead? I think there might be better resources online to help deal with issues I will almost certainly run into on the way (especially not having much experience with the linux command line).

Thank you very much for taking the time to read my questions. If you can answer any of them, or even provide any general advice, it would be greatly appreciated.

Ubuntu server is not much different from CentOS... you just need to run both servers on different ports, as example apache on 80 and nodejs on 8000. if you don't want ugly links like http://domain.com:8000 , then you will need to setup nginx in front of apache and nginx, it will redirect different domains on those servers and will cache static data. it is the most common setup
here some article to help you with nginx https://www.digitalocean.com/community/articles/how-to-configure-nginx-as-a-front-end-proxy-for-apache ignore Ubuntu apt-get, use CentOS yum install instead

It's also easy to have Node proxy to your Apache server.

var express = require('express');
var request = require('request');
var app = express();

app.all('/php/*', function (req, res) {
  req.pipe(request('http://localhost:8000' + req.url)).pipe(res);
});


app.listen(8080);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM