Configure apache for nodejs application alias?

I have a PHP application that is submitted via apache to port 80. I have a nodejs application that works autonomously on port 3000. I want to make ajax requests from client-side code generated by PHP into a nodejs application. The problem in the same origin policy will not allow the use of a different port, and I cannot run both nodejs and apache on port 80.

I would like them both to work on port 80 from a client perspective. How to configure apache to redirect / alias / any specific requests to nodejs application?

Hope this makes sense. Note. Not sure if this is possible, or if I'm going to do it right, open the sentences.

+7
source share
1 answer

You can do this with reverse proxying. Add mod_proxy and configure the location in your primary domain in the vhost file for the proxy server to port 3000 on localhost. Basically something like:

<VirtualHost *:80> ServerName example.com <Location /api> ProxyPass /api http://localhost:3000/ ProxyPassReverse /api http://localhost:3000/ </Location> </VirtualHost> 
+8
source

All Articles