简体   繁体   中英

Heroku PHP app with Node.js app in subfolder, or AWS

How can I configure Heroku, or AWS, so I have a PHP app with a Node.js app running in a subfolder?

I would like to achieve this:

web/app.php       <-- PHP entry point (Symfony front controller)
web/proxy/        <-- Node.js entry point
app.js            <-- Node.js app

My Node.js app will be this web proxy: https://github.com/nfriedly/node-unblocker

I've tried this Heroku buildpack https://github.com/dzuelke/heroku-multipack-nodejs-php-example but this seems to just use Node.js for installing Bower dependencies rather than creating a Node.js server.

Is my desired setup possible or is there some better solution? I need the PHP app and the Node.js web proxy to be running on the same domain.

UPDATE

Thanks to @mbaird 's suggestions I'm now beginning to understand this more and after some more Googling I've managed to get this working locally using Apache proxy, like this:

<Location "/proxy">
    ProxyPass http://localhost:8080/proxy
    ProxyPassReverse http://localhost:8080/proxy
</Location>

Port 8080 is where my local Node.js server is listening.

However I've read mixed reviews about this solution. For example : "this solution is far from optimal. Every request that comes in through Apache will cause an Apache thread to wait/block until the response is returned from your Node.js process."

iaincollins suggests using "HA Proxy or Varnish to pass different paths through to different servers". I'm wondering if this is indeed better then perhaps the best solution for both AWS or Heroku would be to use CloudFront 's Path Pattern to direct different paths to different origins.

Does this sound like a better solution?

Also regarding ElasticBeanstalk, isn't this really just a package of several services including EC2, so shouldn't it be possible to install a Node.js server on the ElasticBeanstalk EC2 instance? I could use separate EC2 instances for PHP and Node.js but that would be more expensive, at least currently while I'm only using 1 instance.

I have no idea how you would do that on Heroku, if it is even possible there. On AWS you could setup Apache on an EC2 server. Apache would be configured to serve your PHP application at a certain path, and proxy requests to the NodeJS app on other URL paths.

Edit to answer questions in comments:

  1. You won't be able to deploy two applications (PHP and Node) in one Elastic Beanstalk environment.
  2. It is definitely a security issue to store the NodeJS application code inside your Apache public folder. Also, you can't serve a NodeJS application that way anyway. You would run NodeJS as a separate server on a separate port, installed in a separate directory, or even on an entirely different server.
  3. This really isn't an AWS specific question. There is no need to limit yourself to AWS tutorials. Just search for something like "NodeJS Apache Proxy" on Google and you will find tons of tutorials.

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