【问题标题】:Reverse proxy on Apache server, without access to configuration filesApache 服务器上的反向代理,无需访问配置文件
【发布时间】:2019-12-17 20:57:27
【问题描述】:

托管服务提供商的默认 Apache 配置在端口号 80 上运行。由于 Apache 配置无法更改,因此必须使用 domain.name:port 访问运行在同一服务器上的 Node 应用程序。

什么样的反向代理可以用来拦截传入的请求并将它们转发到特定的端口?例如:

domain1.name:80 -> default (domain1dir/index.php)
domain2.name:80 -> localhost:8001 (NodeJS)
domain3.name:80 -> localhost:8002 (NodeJS)

由于 Node 无法与 Apache 并行侦听端口号 80,因此我只想到了 PHP 反向代理。 PHP 中是否存在相对直接的解决方案?是否有替代方案?

【问题讨论】:

    标签: php node.js apache proxy


    【解决方案1】:

    您可以试试这个:在您网站的根文件夹中,使用以下内容创建名为.htaccess 的文件:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} =domain2.name
    RewriteRule ^ http://localhost:8001{REQUEST_URI} [P]
    RewriteCond %{HTTP_HOST} =domain3.name
    RewriteRule ^ http://localhost:8002{REQUEST_URI} [P]
    

    (这需要您的托管服务提供商启用mod_proxymod_rewrite

    【讨论】:

    • 您好 Dusan,感谢您的回答。有没有办法检查是否通过命令行启用了 mod_proxy 和 mod_rewrite?
    • 试试apachectl -M
    猜你喜欢
    • 2017-10-24
    • 2017-04-21
    • 2011-01-01
    • 2015-04-26
    • 2014-06-20
    • 2013-04-02
    • 2022-01-01
    • 2018-08-23
    • 2020-09-07
    相关资源
    最近更新 更多