我正在尝试配置设置中的 000-default.conf
文件(Apache2)来要求对某些URL进行认证,而不是其他。
诀窍是,我需要在位置字符串的中间加入一个通配符。我希望通过一些例子来说明我需要完成的任务。
例子1.我需要在URL中加入一个通配符。
a) https://example.com/doc/10.0/TopNav/Default.htm
<-不应要求认证
b) https://example.com/doc/10.0/TopNav/Content/fubar.htm
<-应要求认证
c) https://example.com/doc/10.0/TopNav/Content/Resources/styles.css
<- 不应要求认证(否则Default.htm将无法正常显示)。
d) https://example.com/doc/10.0/TopNav/Content/Public/*
<-这个目录下的所有文件都不需要认证(发布说明等)。
例2.在此目录下的所有文件都不需要认证(发布说明等)。
a) https://example.com/doc/20.0/TopNav/Default.htm
<-不应要求认证
b) https://example.com/doc/20.0/TopNav/Content/fubar.htm
<-应要求认证
c) https://example.com/doc/20.0/TopNav/Content/Resources/styles.css
<- 不应要求认证(否则Default.htm将无法正常显示。
d) https://example.com/doc/20.0/TopNav/Content/Public/*
<-这个目录下的所有文件都不需要认证。
例3:
a) https://example.com/doc/current/TopNav/Default.htm
<-不应要求认证
b) https://example.com/doc/current/TopNav/Content/fubar.htm
<-应要求认证
c) https://example.com/doc/current/TopNav/Content/Resources/styles.css
<- 不应要求认证(否则Default.htm将无法正常显示)。
d) https://example.com/doc/current/TopNav/Content/Public/*
<-这个目录下的所有文件都不应该需要认证(发布说明等)。
好的。那么从模式上看。
/doc/VERSION/TopNav/Content
/doc/VERSION/TopNav/Content
可以要求认证。VERSION
是一个变量,可以包含4到7个字符(例如。10.1
, 12.2
, 14.1
, current
)所以,我在我的 "我的 "里有以下位置 000-default.conf
文件(不包括所有的瓜子端点和证书文件,因为这些都是工作的)。
<Location />
# This location will disable authentication at the site root. This works
MellonEnable "off"
</Location>
<LocationMatch "/TopNav/Content/">
# This location will enable authentication for this and child folders. This works
AuthType Mellon
MellonEnable auth
Require valid-user
</LocationMatch>
<LocationMatch "/TopNav/Content/Resources/*">
# This location should disable authentication for all folders (and children) of this folder name. This does not work.
MellonEnable off
</LocationMatch>
<LocationMatch "/TopNav/Content/Public/*">
# This location will disable authentication for all folders (and children) of this folder name.
MellonEnable off
</LocationMatch>
#
#
# The following were my attempts to use RegEx to accomplish what I need; They didn't work either.
# <LocationMatch "\/Resources\/">
# MellonEnable off
# </LocationMatch>
# <LocationMatch "\/doc\/.{4,7}\/TopNav\/Content\/Resources\/">
# # The Regex test is located at https://regex101.com/r/j5Wo9q/2 where you can see it matches the query strings I need
# MellonEnable off
# </LocationMatch>
#
#
# The following were my attempts to use wildcards. That didn't work either
# <Location "/doc/*/TopNav/Content/Resources/*">
# MellonEnable off
# </Location>
# <Location "/doc/*/TopNav/Content/Resources/">
# MellonEnable off
# </Location>
很抱歉我的问题这么长 但我很难找到好的文档来说明这个问题 Location
指令。我在这里看了11个问题,都没有找到答案。我读了文档,在 http:/httpd.apache.orgdocscurrentmodcore.html#location。 但他们并没有谈到我的具体问题,只是在使用regex与 LocationMatch
但我也不能让它工作。
我希望能得到任何帮助,让它正常工作。