【问题标题】:apache proxypass from subdomain来自子域的 apache proxypass
【发布时间】:2014-04-30 05:32:24
【问题描述】:

我想将 apache2 中的代理从子域传递到像这样的其他端口

http://test1.example.com -> http://test1.example.com:6543

无论如何要编写配置文件,但不是针对此子域,而是针对所有子域

无论如何,例如 http://.*.example.com -> http://.*.example.com:6543

和 http://.*.example.com/first/second -> http://.*.example.com:6543/first/second

这是我的配置

<VirtualHost *:80>
ServerName example.com
ProxyPassMatch ^([^.]+)\.example\.com(.*) http://$1.example.com:6543/$2
ProxyPassReverse /  http://example.com
</VirtualHost>

【问题讨论】:

    标签: regex apache mod-proxy proxypass


    【解决方案1】:

    为此,您需要mod_rewrite。它可以代理[P]。按如下方式使用(去掉VirtualHost标签以满足语法高亮):

    ServerName example.com
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
    RewriteRule ^(.*) http://%1.example.com:6543/$1 [P]
    

    %1是子域,条件匹配,$1是路径,规则匹配。


    您也可以不使用RewriteCond,只使用

    RewriteRule ^(.*) http://%{HTTP_HOST}:6543/$1 [P]
    

    我使用了上面的额外步骤以使其提供更多信息,例如如果你想use the subdomain in the path

    【讨论】:

      猜你喜欢
      • 2020-03-30
      • 2012-08-29
      • 1970-01-01
      • 2015-01-19
      • 2013-03-13
      • 2020-06-06
      • 2013-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多