【问题标题】:Apache mod rewrite to direct from one server to anotherApache mod 重写以直接从一台服务器到另一台服务器
【发布时间】:2013-01-03 10:34:54
【问题描述】:

我必须运行 apache 网络服务器。一个在 80 端口,另一个在 8077 端口。

如果可能,我想尝试通过端口 80 版本重定向所有流量。

我最想要的是能够去http://translate.example.com 并且流量被定向到http://www.example.com:8077

我已经在主端口 80 服务器上进行了很多 mod_rewrite,但我不确定哪些服务器需要配置,或者两者是否都需要。

我想确保 translate.example.com/img(或任何其他子目录)实际上指向 8087/images 目录。

更新

我现在有以下内容:

RewriteCond %{HTTP_HOST} example[NC]
RewriteCond %{REQUEST_URI} ^/glot$ [NC]
RewriteRule    ^(.*)$  http://www.example.com:8077/$1  [P]
ProxyPassReverse / http://www.example.com/

我正在查看其他服务器的新页面,但我发现所有资源都找不到,例如图像、css 等

查看源代码已安装产品中的所有资源都设置有前导斜杠

例如

/img/glotpress-logo.png

所以我不确定如何加载资源。 请注意,如果原始起点是 www.example.com/glot 而不是原始问题中的 glot.example.com,我很高兴

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    您可以将您的资源重新映射到另一台服务器,但将另一台服务器置于非默认端口上可能会阻止您的一些访问者查看它们,因为他们可能会被阻止(防火墙)访问该端口。如果您不担心端口被阻塞,您可以使用mod_rewrite Remapping Resources. 方法。

    RewriteEngine On
    RewriteRule ^/images/(.+) http://www.example.com:8077/images/$1 [R,L]
    

    如果您想确保每个人都能够查看外部资源,您需要使用代理,其中 apache 会透明地将访问者连接隧道连接到 example.com:8077。您可以在 apache 网站上阅读更多关于 mod_rewrite for Proxying 的信息。

    RewriteEngine  on
    RewriteBase    /images/
    RewriteRule    ^images/(.*)$  http://example.com:8077/images/$1  [P]
    ProxyPassReverse /images/ http://example.com/images/
    

    更新

    你有没有试过删除

    RewriteCond %{HTTP_HOST} example[NC] 
    

    这一行基本上告诉它只有在 HTTP_POST 是 example.com 时才会处理,如果它来自 www.example.com,则此规则不适用。我希望“example [NC]”是一个错字。

    最后大概是这样的

    RewriteRule ^/glot/(.*)$ http://www.example.com:8077/glot/$1 [P] 
    ProxyPassReverse /glot/ http://www.example.com:8077/glot/
    

    【讨论】:

    • 您是否尝试过删除 RewriteCond %{HTTP_HOST} example[NC] 这行基本上告诉它只有在 HTTP_POST 是 example.com 如果它来自 example.com 时才会处理此规则不适用.我希望“example [NC]”是一个错字。最后它看起来像 RewriteRule ^/glot/(.*)$ example.com:8077/glot/$1 [P] ProxyPassReverse /glot/ example.com:8077/glot
    【解决方案2】:

    您需要在80端口服务器上进行配置,使其充当8077服务器的代理。

    Apache 文档在这里:http://httpd.apache.org/docs/trunk/rewrite/proxy.html

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2014-02-12
      • 2019-04-15
      • 1970-01-01
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多