【发布时间】:2016-10-19 09:59:11
【问题描述】:
我必须修改通过我在 apache http 服务器中设置的代理重写指令传递的响应标头。
这个简单的例子一切正常,它无条件地从后端服务器为所有请求传递目标:
<VirtualHost ...>
...
# unconditionally modify headers
Header set Content-Type "text/html"
Header unset Content-Disposition
Header unset Content-Transfer-Encoding
# fetch goal from backend
RewriteEngine on
SSLProxyEngine on
RewriteRule ^ https://back.example.org/goal [P]
...
# prevent all access to the file system
DocumentRoot /var/www/html
<Directory /var/www/html>
Options none
Order deny,allow
Deny from All
</Directory>
</VirtualHost>
但是问题是主机还必须从另一个后端服务器传送一些静态文件,其中标头必须不被更改!所以我尝试在第一步重写虚拟目标,应用标题修改规则,然后在第二步进行代理:
<VirtualHost ...>
...
# modify headers only for /goal
<Location /goal>
Header set Content-Type "text/html"
Header unset Content-Disposition
Header unset Content-Transfer-Encoding
</Location>
# fetch static exceptions from static backend
RewriteEngine on
SSLProxyEngine on
RewriteRule static-1$ https://static.example.org/static-1 [P]
RewriteRule static-2$ https://static.example.org/static-2 [P]
RewriteRule static-3$ https://static.example.org/static-3 [P]
# two step rewrite and proxy to fetch goal from backend and get the headers modified
RewriteRule ^/goal$ https://back.xample.org/goal [P]
RewriteRule ^ /goal [PT,N]
...
# prevent all access to the file system
DocumentRoot /var/www/html
<Directory /var/www/html>
Options none
Order deny,allow
Deny from All
</Directory>
</VirtualHost>
然而,这给我留下了 http 状态 403。
我使用重写日志来进一步了解,实际上根据第一步,请求被重写为/goal,再次调用 URI -to-filehandler API,然后请求被简单地映射到文件系统,这解释了403.为什么下一轮不应用第二个重写步骤,代理步骤?
或者,我的实际问题是:如何将标头修改应用于包罗万象的重写代理规则结果,但从标头修改中定义一些明确的例外?
【问题讨论】:
标签: apache http-headers mod-proxy