9

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.

4

1 回答 1

10

您可以使用反向代理来做到这一点。添加 mod_proxy 并在 vhost 文件中的主域下设置一个位置,以代理到 localhost 上的端口 3000。基本上是这样的:

<VirtualHost *:80>
 ServerName example.com
 <Location /api>
   ProxyPass /api http://localhost:3000/
   ProxyPassReverse /api http://localhost:3000/
 </Location>
</VirtualHost>
于 2011-06-25T19:29:39.630 回答