car*_*lve 3 php azure azure-web-sites azure-app-service-envrmnt
我有一个基于Laravel 4的PHP应用程序,我已经成功地在Azure Web应用程序中工作,我遇到的唯一问题是当我尝试访问文件时,example.azurewebsites.net/js/vendor/jquery.slicknav.min.js我得到"您无权查看此目录或页面. " 响应.
该文件夹site/wwwroot是我放置所有Laravel应用程序文件的地方,对于那些不熟悉Laravel的人,它包含四个文件夹:app,Bootstrap,public和vendor.
我已在Azure门户中设置虚拟应用程序和目录设置,以映射/到site\wwwroot\public公共目录并在其中放置web.config文件,其中包含以下内容:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/>
<staticContent>
<remove fileExtension=".svg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains"/>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="X-Requested-With,Content-Type" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,DELETE,PUT,PATCH" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<rule name="Laravel4" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
通过此设置,重写按预期工作,除非文件夹名称包含app,Bootstrap,public或vendor example.azurewebsites.net/js/vendor/jquery.slicknav.min.js.
我的问题是如何修改我的重写规则来解决这个问题?如果我site\wwwroot\public\js\vendor\通过在末尾添加连字符来重命名文件夹,它将起作用.我也多次重启容器.
编辑为了更加清晰,这是我的目录结构:
?? wwwroot
? ?? app
? ?? bootstrap
? ?? public
? ? ?? css
? ? ?? files
? ? ?? fonts
? ? ?? imgs
? ? ?? js
? ? ? ?? admin
? ? ? ?? app
? ? ? ? ?? link-check.js
? ? ? ?? old
? ? ? ?? vendor
? ? ? ? ?? sortable.min.js
? ? ?? less
? ? ?? packages
? ? ?? tmp
? ? ?? uploads
? ?? vendor
?? ...
Run Code Online (Sandbox Code Playgroud)
我可以访问我的web.config配置link-check.js,example.azurewebsites.net/js/app/link-check.js而sortable.min.js 无法访问example.azurewebsites.net/js/vendor/sortable.min.js(并且/ js/vendor路径中没有其他内容可访问).
注:如果我重新命名wwwroot\public\js\vendor到wwwroot\public\js\vendor-我可以看到sortable.min.js从example.azurewebsites.net/js/vendor-/sortable.min.js
事实证明,vendor在路径中返回403禁止的所有文件夹的原因是我安装了Azure作曲家Web应用程序扩展.在该applicationHost.xdt扩展名的文件中,它设置以下重写:
<rewrite xdt:Transform="InsertIfMissing">
<rules xdt:Transform="InsertIfMissing">
<rule name="RequestBlockingRule1" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{URL}" pattern="vendor/(.*)$" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
对我来说,删除扩展明显解决了问题,但是我觉得添加<clear/>到我的重写规则部分将清除扩展设置的规则并修复问题.
为了将来参考,该问题是针对2015年11月7日和2015年7月23日的延期提出的.
<clear/>用于修复问题的修改后的web.config<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/>
<staticContent>
<remove fileExtension=".svg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains"/>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="X-Requested-With,Content-Type" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,DELETE,PUT,PATCH" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<clear/>
<rule name="Laravel4" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)