Apache 2.4不使用适用于2.2

时间:2015-09-23 09:03:25

标签: apache mod-rewrite proxy

我在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可能还需要其他东西吗?

感谢。

1 个答案:

答案 0 :(得分:0)

您有两个小问题:

Apache2.4需要一个不同的字符串开始锚点:

RewriteRule /images/here/

应该是:

RewriteRule ^images/here/

你的旗帜可能会导致问题: