【发布时间】: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 是否都已启用。我还尝试使用服务器上的curl 和wget 访问图像,它可以使图像正常,所以这不是服务器无法访问图像的网络问题。
同样的规则适用于 CentOS 6 和 7 机器上的 Apache 2.2。
我现在不知道为什么它不起作用。也许 2.4 中还需要其他东西?
谢谢。
【问题讨论】:
标签: apache mod-rewrite proxy