gpt4 book ai didi

Apache RewriteRule 代理不遵循重定向

转载 作者:行者123 更新时间:2023-12-05 07:46:23 27 4
gpt4 key购买 nike

我正在尝试使用 mod_proxy 配置 Apache 2.4 作为反向代理,但我遇到了重定向未从源服务器传递到客户端的问题。

我在虚拟主机配置中有如下配置:

[...]
ProxyPreserveHost On
# ProxyPass "/" "http://old.domain.tld/"
ProxyPassReverse "/" "http://old.domain.tld/"
[...]

在虚拟主机配置中使用注释掉的 ProxyPass 指令时,一切正常。这意味着来自源服务器的 30 倍重定向被正确重写并转发给客户端。

在 .htaccess 中配置 ProxyPass 时(我需要它,因为这只应在特定条件下发生),反向代理工作正常,只是它不处理任何到客户端的重定向。

我有以下 .htaccess:

RewriteEngine On
RewriteRule ^(.*)$ http://old.domain.tld/$1 [P]

现在,当源服务器发送 30x-Redirect 时,我总是会收到 404 - not found in client。

在代理服务器日志中,我可以看到以下痕迹:

[...] strip per-dir prefix: /[...]/domain.tld/htdocs/ ->
[...] applying pattern '^(.*)$' to uri ''
[...] rewrite '' -> 'http://old.domain.tld/'
[...] escaped URI in per-dir context for proxy, http://old.domain.tld/ -> http://old.domain.tld/
[...] forcing proxy-throughput with http://old.domain.tld/
[...] go-ahead with proxy request proxy:http://old.domain.tld/ [OK]

客户端获取以下传递的 header :

HTTP/1.1 404 Not Found
Date: Fri, 25 Nov 2016 14:04:23 GMT
Server: Apache/2
Content-Length: 1060
Content-Type: text/html; charset=utf-8
Keep-Alive: timeout=5, max=100
Proxy-Connection: Keep-alive

我不明白为什么 Apache 或 mod_rewrite/mod_proxy 在 .htaccess 中配置时没有转发正确的重定向。

有什么解决办法吗?还是我做错了什么?

谢谢。

最佳答案

ProxyPassReverse 其指定处理重定向,因此源服务器不会将客户端带到代理之外。

This directive lets Apache adjust the URL in the Location, Content-Location and URI headers on HTTP redirect responses. This is essential when Apache is used as a reverse proxy (or gateway) to avoid bypassing the reverse proxy because of HTTP redirects on the backend servers which stay behind the reverse proxy.

Only the HTTP response headers specifically mentioned above will be rewritten. Apache will not rewrite other response headers, nor will it rewrite URL references inside HTML pages. This means that if the proxied content contains absolute URL references, they will bypass the proxy. A third-party module that will look inside the HTML and rewrite URL references is Nick Kew's mod_proxy_html.

关于Apache RewriteRule 代理不遵循重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40807260/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com