大网数据广告活动
服务器运维问答

Use ProxyPassMatch on all URLs except the root path

· 52CE 我爱测

I have searched high a low for a solution for this, and hoping it is just me. What I'm trying to do is redirect all traffic from a URL we host, to another server managed by another provider we purchase from so we can customize th…

问题原文

原帖链接 · Sillyfrog · CC BY-SA 3.0

I have searched high a low for a solution for this, and hoping it is just me. What I'm trying to do is redirect all traffic from a URL we host, to another server managed by another provider we purchase from so we can customize the root URL.

I'm using httpd 2.2.3 (Apache). This is configured in a VirtualHost section, it is also SSL (I don't think that should matter however).

Everything works great, except the exclusion.

What I have (simplified) is:

ProxyPreserveHost On

<VirtualHost 1.2.3.4:443>        SSLProxyEngine On
    ProxyPassMatch ^/$   !
    ProxyPassMatch ^/(.*)$      https://proxy.example.com/$1
    ProxyPassReverse /  https://proxy.example.com/

    SSLEngine on
    ...

</VirtualHost>

However it always goes to the remote site. I have tried a bunch of combinations such as:

    ProxyPassMatch /$   !
    ProxyPassMatch ^/(.*)$      https://proxy.example.com/$1
    ProxyPassMatch com/   !
    ProxyPassMatch ^/(.*)$      https://proxy.example.com/$1

I also tried going the other way (to match anything with something after the /, ie:

    ProxyPassMatch ^/(..+)$     https://proxy.example.com/$1
    ProxyPassMatch /    !
    ProxyPassMatch ^/(..*)$     https://proxy.example.com/$1
    ProxyPassMatch /    !

Now the documentation says it matches the URL, but I have found no evidence that this is what it actually does (ie: second variant above with com/).

I have also tried a bunch of other combinations which either match everything, or match nothing.

My thinking is I'm not understanding the URL that is getting given to the regular expression, but not sure how to look at it. I have turned up the debug level in Apache to debug, and it does not give anything useful either.

Cheers.

已采纳解答

原帖链接 · Sillyfrog · CC BY-SA 3.0

I figured out an answer, or more of a work around: to use another server (in this case a local server still on the same httpd instance).

ie: The lines above now read:

ProxyPassMatch ^/$ 127.0.0.1:81
ProxyPassMatch ^/(.*)$ proxy.example.com/$1 

(plus the usual host config to run on a new port, and config of a virtual host on that port). It is a bit messy, but appears to sort it out!

I'm still keen to know if I have done something wrong and there is a "correct" answer to this - as I consider this a bit of a hack.

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

资料来源与适用范围

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

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

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