Apache和nodejs公用80端口的问题

Apache开启反向代理,启用的vhost文件为

<VirtualHost *:80>
  ServerAdmin admin@gmail.com
  ServerName localhost
  ServerAlias localhost

  ProxyRequests off

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  <Location />
    ProxyPass http://localhost:9000/
    ProxyPassReverse http://localhost:9000/
  </Location>


</VirtualHost>

但这样代理的效果是,所有80端口的请求都被nodejs接受了,Apache上其他的目录没法访问。怎样能做到Apache和nodejs真正公用80端口呢?

阅读 9.3k
4 个回答

这是我们在项目中用到的一个转发,实践证明是不会将所有的80端口都转发到9000,这是基于域名来判断是否需要转发,可以参考下。

<VirtualHost *:80>
    ServerName www.test.com
    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass / http://127.0.0.1:9000/
    ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>

通过

ServerName ooxx.com
ServerAlias *.ooxx.com

来区分。

最好通过是使用不同的域名来进行区分

新手上路,请多包涵
<VirtualHost *:80>
  ServerAdmin admin@gmail.com
  ServerName localhost
  ServerAlias localhost

  ProxyRequests off
  DocumentRoot /path/to/document_root
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  <Location />
    ProxyPass / http://localhost:9000/
    ProxyPassReverse / http://localhost:9000/
    ProxyPass /forward/no_reverse_proxy !
  </Location>


</VirtualHost>

此时,/path/to/document_root/forward/no_reverse_proxy 目录下的网页(或php文件)会被(解析并)显示.也就是说http://localhost/forward/no_reverse_proxy没有被反代

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题