【问题标题】:Apache load balancing with RewriteCond not working?使用 RewriteCond 的 Apache 负载平衡不起作用?
【发布时间】:2016-02-23 22:38:07
【问题描述】:

我已经安装了 apache httpd 服务并尝试设置负载平衡。 我想在特定条件下重写请求 - 当 Host 标头为“images.server.com”时,我想重写请求,将“/images/”添加到 URI,然后将其代理到我的上游服务器。 mod_proxy 模块非常适合这项任务:https://httpd.apache.org/docs/current/rewrite/proxy.html 好吧,不太好 - 我的设置如下:

    <Proxy balancer://mycluster>
      BalancerMember http://xxx.xx.xx.xx:8080
    </Proxy>
    ProxyPreserveHost On
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ="images.server.com"
    RewriteRule "/(.*)" "/images/%1" [P]
    ProxyPass /images balancer://mycluster/images

它不工作:( 请帮我找出这个配置的缺陷在哪里。

附:我已经加载了模块:

    LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule proxy_module modules/mod_proxy.so

【问题讨论】:

  • 你观察到了什么?为什么不使用虚拟主机并完全省略重写?

标签: apache mod-rewrite load-balancing httpd.conf mod-proxy


【解决方案1】:

不要同时使用“P”标志和 ProxyPass。如果您要使用“P”标志,请在替换中使用 balancer://... 并完全删除 ProxyPass。

【讨论】:

  • 我删除了ProxyPass...同样的结果
  • 您是否更改了重写器中的替换?到什么?你观察到了什么?
  • 是的。 RewriteRule /(.*) balancer://mycluster/images/%1 [P] 行为是一样的:404,就好像它搜索没有/images/部分的位置
  • 进度:我从写入条件中的字符串值中删除了引号,现在它被重定向到 images.server.com 但在 https
猜你喜欢
  • 2015-02-11
  • 2023-03-14
  • 2015-08-07
  • 2012-12-19
  • 2018-11-22
  • 2018-03-12
  • 2012-06-04
  • 2012-08-24
  • 1970-01-01
相关资源
最近更新 更多