cac*_*bre 5 proxy httpd pcre apache-2.2
我正在尝试创建一个反向代理,它匹配除 Apache 2.2 中的一个之外的每个 URL。它适用于 Apache 2.4 (Centos 7),但不适用于 Apache 2.2 (Centos 6.6) ...
# Do not modify this
<LocationMatch "^/my-website-2">
ProxyPass http://X.X.X.X:PORT/my-website-2
ProxyPassReverse http://X.X.X.X:PORT/my-website-2
(...)
</LocationMatch>
# Match every URL except the one finishing with /redirect
<LocationMatch "^/my-website(?!/redirect)">
ProxyPass http://X.X.X.X:PORT/my-website
ProxyPassReverse http://X.X.X.X:PORT/my-website
AuthType XXX
RequestHeader set XXX YYY
(...)
</LocationMatch>
# Do anothers directives with this URL only, finishing with /redirect
<Location "/my-website/redirect">
AuthType XXX
(...)
</Location>
Run Code Online (Sandbox Code Playgroud)
当我输入https://my-server.com/my-website因为正则表达式不匹配 ^/my-website时,我的服务器正在寻找 /var/www/html/my-website(不存在的)(?!/重定向)
我知道 Apache 2.2 不能理解每个负面 PCRE 正则表达式,但似乎存在一些技巧......请参阅:
然后,我尝试一个简单的正则表达式:
<LocationMatch "/my-website(.*)">
Run Code Online (Sandbox Code Playgroud)
...而且它似乎甚至不被解释为 PCRE ...在这个用例中,如果我在 URL 中输入 /my-website(.*) ,它就可以工作。
与(来自http://httpd.apache.org/docs/2.2/en//mod/core.html#locationmatch)相同的行为:
<LocationMatch "/(extra|special)/data">
Run Code Online (Sandbox Code Playgroud)
...我需要在浏览器的 URL 栏中输入http://my-server.com/(extra|special)/data。
Apache HTTPd 2.2 是否需要额外的包来理解 LocationMatch 中的 PCRE?
已安装的软件包:
httpd.x86_64 2.2.15-60.el6.centos.6
apr.x86_64 1.3.9-5.el6_9.1 @Default_Organization_CentOS_6_CentOS_6_Update_x86_64
apr-util.x86_64 1.3.9-3.el6_0.1 @in-std
pcre.x86_64 7.8-7.el6 @Default_Organization_CentOS_6_CentOS_6_Base_x86_64
pcre-devel.x86_64 7.8-7.el6 @Default_Organization_CentOS_6_CentOS_6_Base_x86_64
Run Code Online (Sandbox Code Playgroud)
奇怪的 ...
谢谢
小智 0
您需要使用ProxyPassMatch
而不是ProxyPass
.
根据上面的示例进行了更新,并进行了其他重要更改:
# Do not modify this
<LocationMatch "^/my-website-2">
ProxyPassMatch http://X.X.X.X:PORT
ProxyPassReverse http://X.X.X.X:PORT
(...)
</LocationMatch>
# Match every URL except the one finishing with /redirect
<LocationMatch "^/my-website(?!/redirect)">
ProxyPassMatch http://X.X.X.X:PORT
ProxyPassReverse http://X.X.X.X:PORT
AuthType XXX
RequestHeader set XXX YYY
(...)
</LocationMatch>
# Do anothers directives with this URL only, finishing with /redirect
<Location "/my-website/redirect">
AuthType XXX
ProxyPassMatch http://X.X.X.X:PORT
ProxyPassReverse http://X.X.X.X:PORT
(...)
</Location>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1167 次 |
最近记录: |