1

我正在尝试使用 mod_rewrite 将多个域映射到一台主机上的不同 servlet。例子:

www.dom1.com -> 192.168.1.n/dom1

www.dom2.com -> 192.168.1.n/dom2 ...

我正在使用 mod_rewrite 和 mod_proxy 以及 VirtualHost 指令,但似乎通过 ProxyPassReverse 进行的反向映射无法按我的预期工作。

ProxyPassReverse /subdomain.domain.com http://192.168.1.n/subdomain

不起作用。我已经打开了重写登录

RewriteLog /var/log/rewrite.log

从日志中我会说重写有效,问题似乎与反向映射有关。但是我看不到任何反向映射条目。似乎没有记录反向映射或需要激活不同的命令。(Apache 和 servlet 容器位于不同的机器上,但我认为这无关紧要吗?)

4

1 回答 1

2

毕竟我找到了适合我的解决方案。这是我的配置的摘录,显示了域 1 的一个虚拟主机

<VirtualHost *>
  ServerName www.dom1.com
  ServerAlias dom1.com

  RewriteEngine On

  # logs might be omitted
  RewriteLog /var/log/dom1_rewrite.log
  RewriteLogLevel 2
  CustomLog /var/log/dom1_custom.log common
  ErrorLog /var/log/dom1_error.log

  # rewrite to internal ip
  RewriteRule ^/(.*) http://192.168.1.105/dom1/$1 [L,P,E=proxy_ok:1]

  # Preserve the host-part in the forwarded url
  ProxyPreserveHost On

  # Substitute responses with the original
  ProxyPassReverse / http://192.168.1.105/dom1/
  ProxyPassReverse / http://192.168.1.105/dom1
  ProxyPassReverse / http://dom1.com/dom1/
  ProxyPassReverse / http://dom1.com/dom1
</VirtualHost>

我的第一个配置出了什么问题 - 我必须保留主机,然后添加所有必要的 ProxyPassReverse 规则来替换响应。

这是我的 mod_proxy 配置:

<IfModule mod_proxy.c>
        #turning ProxyRequests on and allowing proxying from all may allow
        #spammers to use your proxy to send email.

        ProxyRequests Off

        <Proxy *>
                AddDefaultCharset off
                Order deny,allow
                Deny from all

               # Proxies just in case Proxy_ok is set
               Allow from env=proxy_ok
        </Proxy>

        # Not sure whether we need this ...
        # Enable/disable the handling of HTTP/1.1 "Via:" headers.
        # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
        # Set to one of: Off | On | Full | Block
        ProxyVia On
</IfModule>

可能有更清洁的解决方案,但是 - 如果可以正常工作。

于 2010-04-15T15:27:18.967 回答