【问题标题】:Apache mod_rewrite and multiple domainsApache mod_rewrite 和多个域
【发布时间】:2011-02-04 13:08:01
【问题描述】:

我正在尝试使用 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 容器位于不同的机器上,但我认为这无关紧要吗?)

【问题讨论】:

    标签: apache mod-rewrite mod-proxy


    【解决方案1】:

    毕竟我找到了适合我的解决方案。 这是我的配置的摘录,显示域 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>
    

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

    【讨论】:

      猜你喜欢
      • 2011-05-03
      • 2011-04-23
      • 2013-04-24
      • 2010-09-18
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多