大网数据广告活动
网站运营与故障问答

Functional difference between proxypass and proxypassreverse in Apache

· 52CE 我爱测

The official document states that: The ProxyPass configures the server to fetch the appropriate documents, while the ProxyPassReverse directive rewrites redirects originating at internal.example.com so that they target the approp…

问题原文

原帖链接 · Lunartist · CC BY-SA 4.0

The official document states that:

The ProxyPass configures the server to fetch the appropriate documents, while the ProxyPassReverse directive rewrites redirects originating at internal.example.com so that they target the appropriate directory on the local server.

From that I understand that ProxyPassReverse rewrites the header. But why do you need ProxyPass for? Why isn't ProxyPassReverse itself enough? What exactly does ProxyPass do?

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 4.0

ProxyPass by itself enables the reverse proxy functionality and in some cases that is enough. For example ProxyPass / http://localhost:8080/ configures Apache to proxy the site from a back end server.

This works pretty well until the back end wants to issue redirects. Redirects have to be to fully qualified absolute URLs. To redirect /foo to /bar the back end would respond with a redirect response with Location: http://localhost:8080/bar. If that got proxied directly to the client, the redirect would break.

One solution to this problem would be to reconfigure the back end to know that it is serving http://mysite.example and not http://localhost:8080. Then it could use the correct absolute redirects. This could even be done dynamically by having the back end examine X-Forwarded-For headers that tell it when it is behind a reverse proxy or send the Host: header to the backend with ProxyPreserveHost.

However, not all back ends support such configuration. If not you can use the ProxyPassReverse directive to change the Location header on the response. That configuration only exists to fix broken redirects from the back end.

Similarly ProxyPassReverseCookieDomain is meant to fix when the back end tries to set cookies for the wrong domain. You can even install mod_proxy_html to parse all the HTML from the back end and fix any absolute links within the HTML documents.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2023-08-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。