I have a PHP application being served through apache on port 80. I have a nodejs application running standalone on port 3000. I want to make ajax requests from the client side code generated by PHP to the nodejs application. The problem is the same origin policy won't allow a different port, and I can't run both nodejs and apache on port 80.
What I would ideally like to do is have them both appear to run on port 80 from the client's perspective. How can I set up apache to reroute/alias/whatever certain requests to the nodejs application?
Hope that makes sense. Note: Not sure if this is possible, or if I am going about it in the right way - open to suggestions.
The benefits Apache brings to Node. js applications. How to configure Apache for a Node.
If you're prepared to re-write your PHP in JavaScript, then yes, Node. js can replace your Apache. If you place an Apache or NGINX instance running in reverse-proxy mode between your servers and your clients, you could handle some requests in JavaScript on Node.
The response time is almost the same with the lowest concurrency level, but with 250 concurrent requests, NodeJS was five times faster than Apache.
You can do that with reverse proxying. Add mod_proxy and setup a location under your main domain in the vhost file to proxy 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With