将 Grav CMS 部署到 Azure

Deploying Grav CMS to Azure

通过 Bitbucket 存储库将基于 Grav CMS (http://getgrav.org) 的网站部署到 Azure 后,我在尝试浏览该网站时收到消息 "You do not have permission to view this directory or page."。我还没有更改任何配置设置。

由于 Azure 上的 PHP 应用程序 运行 托管在 IIS 上,因此您的问题是由于您没有在 IIS 中配置 URL 重写模式。

尝试在您的应用程序的根目录中创建一个名为 web.config 的文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <remove value="index.php" />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <rule name="request_filename" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
                <rule name="user_accounts" stopProcessing="true">
                    <match url="^user/accounts/(.*)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="user_config" stopProcessing="true">
                    <match url="^user/config/(.*)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="user_error_redirect" stopProcessing="true">
                    <match url="^user/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="cache" stopProcessing="true">
                    <match url="^cache/(.*)" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="bin" stopProcessing="true">
                    <match url="^bin/(.*)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="backup" stopProcessing="true">
                    <match url="^backup/(.*)" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="system" stopProcessing="true">
                    <match url="^system/(.*)\.(txt|md|html|yaml|php|twig|sh|bat)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="vendor" stopProcessing="true">
                    <match url="^vendor/(.*)\.(txt|md|html|yaml|php|twig|sh|bat)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
    <system.web>
        <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,\,?" />
    </system.web>
</configuration>

然后将其与您的应用程序一起部署到 Azure。此外,您可以在 grav 应用程序的 webserver-configs 文件夹中找到此配置文件。或者你可以参考 https://github.com/Vivalldi/grav/blob/develop/webserver-configs/web.config at github.

如有任何疑问,请随时告诉我。

截至 2018 年 3 月,我发现我还需要安装 composer 扩展才能使网站正常加载。

详情见https://docs.microsoft.com/en-gb/azure/app-service/web-sites-php-configure#how-to-enable-composer-automation-in-azure

如果不这样做,我会在尝试加载网站时看到一个空白页面。