Apache ProxyPass - 正则表达式排除文件

问题描述 投票:10回答:2

我试图排除所有以“dgg-”开头并以“.xml”结尾的文件,例如:dgg-file-1.xml使用apache代理。

这有效:

ProxyPass /myfile.xml ! # single file
ProxyPass /directory ! # all files inside dir

这不起作用:

ProxyPass /dgg-(.*)\.xml !

我怎样才能做到这一点?

ps-我在httpd.conf->virtualhost而不是.htaccess中使用此代码。

regex apache mod-rewrite load-balancing proxypass
2个回答
17
投票

使用ProxyPassMatchProxyPass期望完全写入路径元素,它不接受正则表达式。

由于ProxyPassMatch采用正则表达式,这意味着你还必须锚定它:

ProxyPassMatch ^/dgg-[^.]+\.xml$ !

3
投票

我有一种情况,我希望从Apache网络服务器中挑选几张图片,并从应用服务器中包含一些图像(在我的情况下是Jboss)。所以我想要一个必须排除和包含的正则表达式。这是我在VirtualHost标签下添加到httpd.conf文件的内容。

有一些css和js文件位于jsf jars和jenia popup jar中,我们在webserver上找不到它们。所以请联系app server。正则表达式正在查找所有* .js和* .css网址,但不包括任何包含/ jenia4faces和/ faces的网址。这是为了确保仍然从应用服务器中提取这样的脚本/MYWEBAPP/jenia4faces/popup/popupFrame/js/popupFrame.js和/MYWEBAPP/faces/myFacesExtensionResource/tabbedpane.HtmlTabbedPaneRenderer/11302665/dynamicTabs.js。休息所有.js和.css将由网络服务器提供。

  ProxyPassMatch ^(/MYWEBAPP/(?!jenia4faces).*\.js)$ !
  ProxyPassMatch ^(/MYWEBAPP/(?!faces).*\.css)$ !
  ProxyPassMatch ^(/MYWEBAPP/(?!jenia4faces).*\.js)$ !
  ProxyPassMatch ^(/MYWEBAPP/(?!faces).*\.css)$ !

where / MYWEBAPP是我的web应用程序根上下文。另外(?!faces)是告诉URL是否在url路径中没有“faces”。

© www.soinside.com 2019 - 2024. All rights reserved.