【问题标题】:How to Deploy Angular 6 to Azure Web App - You do not have permissions如何将 Angular 6 部署到 Azure Web App - 您没有权限
【发布时间】:2019-02-18 23:59:32
【问题描述】:

我创建了一个干净的 Angular 6 应用程序。我将以下 web.config 添加到 src 文件夹:

<configuration>
<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="/" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

我在 angular.json 文件的资产部分添加了“src/web.config”。我已将 web 应用上的节点版本更新为 10.6。

当我将应用程序和导航部署到站点时,我得到以下信息:您无权查看此目录或页面。

我遵循以下示例: https://itnext.io/easy-way-to-deploy-a-angular-5-application-to-azure-web-app-using-vsts-pipelines-4a288b9deae1

有什么建议吗?

【问题讨论】:

    标签: angular azure


    【解决方案1】:

    我花了很长时间才弄清楚这一点。我希望它有所帮助。

    • 在您的应用服务中,单击“应用程序设置”。滚动到底部。您将看到“虚拟应用程序和目录”。您的虚拟路径应该是“/”,物理路径应该是“site/wwwroot/” 将您的物理路径更改为“site/wwwroot/'appname'” “appname”应该是您的应用程序的名称。或者它应该是“dist”内的任何文件夹。

    【讨论】:

    • 另外,我不必添加 web.config。这个简单的更改为我解决了问题。
    • 此更改也为我解决了问题
    【解决方案2】:

    我不希望您收到此错误消息,但在 web.config 中,我错过了您为 json 文件定义 MimeMap 的部分。请试试这个 web.config:

    <configuration>
        <system.webServer>
            <staticContent>
                <mimeMap fileExtension=".json" mimeType="application/json" />
                <remove fileExtension=".woff"/>
                <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
                <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
         </staticContent>
    
          <rewrite>
            <rules>
                <rule name="Angular" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
            </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    另请参阅:Web.config for hosting an Angular application on Azure Web App

    【讨论】:

    • 感谢您的回复。我刚试过,但一样。我想知道它是否可能与应用服务上的节点版本有关。
    • 我变得更聪明了。我刚刚部署了完整的项目,而不仅仅是 dist 文件夹的内容。但现在我有以下问题。如果你去angtest5.azurewebsites.net 它不会加载任何东西。但是angtest5.azurewebsites.net/index.html。 Web 服务器是节点服务器,如果它不是 IIS 主机,它会读取 web.con 文件吗?另外你知道如何告诉服务器默认加载 index.html 吗?
    猜你喜欢
    • 2018-12-10
    • 1970-01-01
    • 2016-03-25
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多