【问题标题】:Apache 2.4 not proxying via mod_rewrite using rules that work on 2.2Apache 2.4 不使用适用于 2.2 的规则通过 mod_rewrite 进行代理
【发布时间】:2015-12-20 12:23:49
【问题描述】:

我在 Ubuntu 14.04.2 LTS 机器上安装了 Apache 2.4 并添加了我的网站,除了某些图像的代理重写规则外,一切正常。我设置的规则如下:

RewriteEngine on
RewriteRule /images/here/(.*)$ http://my.site.com/images/here/$1 [P,QSA,L]

但是当我尝试访问文件时说:

http://other.site.com/images/here/image.jpg

我在浏览器中收到 404 错误。我打开了重写日志记录,在日志中它似乎与规则匹配并正确应用了代理:

[Wed Sep 23 09:47:16.387531 2015] [rewrite:trace2] [pid 29527:tid 139709285484288] mod_rewrite.c(468): [client 10.0.5.61:51099] 10.0.5.61 - - [other.site.com/sid#7f109fe93400][rid#7f109fe070a0/initial] init rewrite engine with requested uri /images/here/image.jpg
[Wed Sep 23 09:47:16.387700 2015] [rewrite:trace3] [pid 29527:tid 139709285484288] mod_rewrite.c(468): [client 10.0.5.61:51099] 10.0.5.61 - - [other.site.com/sid#7f109fe93400][rid#7f109fe070a0/initial] applying pattern '/images/here/(.*)$' to uri '/images/here/image.jpg'
[Wed Sep 23 09:47:16.387736 2015] [rewrite:trace2] [pid 29527:tid 139709285484288] mod_rewrite.c(468): [client 10.0.5.61:51099] 10.0.5.61 - - [other.site.com/sid#7f109fe93400][rid#7f109fe070a0/initial] rewrite '/images/here/image.jpg' -> 'http://my.site.com/images/here/image.jpg'
[Wed Sep 23 09:47:16.387748 2015] [rewrite:trace2] [pid 29527:tid 139709285484288] mod_rewrite.c(468): [client 10.0.5.61:51099] 10.0.5.61 - - [other.site.com/sid#7f109fe93400][rid#7f109fe070a0/initial] forcing proxy-throughput with http://my.site.com/images/here/image.jpg
[Wed Sep 23 09:47:16.387757 2015] [rewrite:trace1] [pid 29527:tid 139709285484288] mod_rewrite.c(468): [client 10.0.5.61:51099] 10.0.5.61 - - [other.site.com/sid#7f109fe93400][rid#7f109fe070a0/initial] go-ahead with proxy request proxy:http://my.site.com/images/here/image.jpg [OK]

我检查了 mod_rewrite、mod_proxy 和 mod_proxy_http 是否都已启用。我还尝试使用服务器上的curlwget 访问图像,它可以使图像正常,所以这不是服务器无法访问图像的网络问题。

同样的规则适用于 CentOS 6 和 7 机器上的 Apache 2.2。

我现在不知道为什么它不起作用。也许 2.4 中还需要其他东西?

谢谢。

【问题讨论】:

    标签: apache mod-rewrite proxy


    【解决方案1】:

    你有两个小问题:

    Apache2.4 需要不同的字符串起始锚点:

    RewriteRule /images/here/
    

    应该是:

    RewriteRule ^images/here/
    

    您的标志可能会导致问题:

    【讨论】:

    • 感谢您的回复,但这仍然有效。我唯一可以开始工作的是删除所有标志,然后将其 302 转换为图像,这对我来说是可行的,但是我真的很想了解为什么代理不起作用。
    猜你喜欢
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多