在 Proxypass 之前重写规则

Pro*_*e85 7 apache-2.4

有一个应用程序在端口 10001 上运行,我想要一个反向代理来为它提供服务hostname/ds。唯一的问题是有硬链接脚本/scripts/...

这意味着hostname/ds/应让我到达localhost:10001/并且hostname/scripts应该首先将请求 url 重写为hostname/ds/scripts/*.

我的配置:

<VirtualHost *:80>
RewriteEngine on
RewriteRule /^scripts/(.*)$ /ds/scripts/$1 [L,PT]   

ProxyPass /ds/ http://127.0.0.1:10001/
ProxyPassReverse /ds/ http://127.0.0.1:10001/

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

它不起作用:hostname/scripts/获得 404。而hostname/ds/scripts/通过应用程序获得正确答案。

根据/sf/ask/630235091/ PT应该可以工作。我究竟做错了什么?

asd*_*min 6

您的模式中有错字,请尝试^/代替/^(后者永远不会匹配)


Jen*_*y D 5

您也可以通过简单地添加第二个 ProxyPass 来匹配 /scripts 来做到这一点,如下所示:

<VirtualHost *:80>
    ProxyPass /scripts/ http://127.0.0.1:10001/
    ProxyPassReverse /scripts/ http://127.0.0.1:10001/

    ProxyPass /ds/ http://127.0.0.1:10001/
    ProxyPassReverse /ds/ http://127.0.0.1:10001/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)