【问题标题】:Publishing ASP.NET Core application to Azure via PowerShell getting 502 (Bad Gateway) In Azure通过 PowerShell 将 ASP.NET Core 应用程序发布到 Azure,在 Azure 中出现 502(错误网关)
【发布时间】:2016-05-24 13:10:57
【问题描述】:

如何将我的 ASP.NET Core 应用程序发布到 Azure?

到目前为止,我所做的是创建了一个脚本,该脚本是我从 Azure/Microsoft 官方文档中获得的,它调用 Visual Studio 也使用的 default-publish.ps1 脚本。脚本如下:

param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName

# get the scm url to use with MSDeploy.  By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]


$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword}


$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"


. $publishScript -publishProperties $publishProperties  -packOutput $packOutput

现在,如果您提供 Azure 网站名称和 dotnet 发布工件,此脚本将调用 default-publish.ps1 脚本。我已将我的 default-publish.ps1 脚本更新为 repo 中的当前脚本。

问题是当我发布到 Azure 时返回 502 Bad Gateway 错误。即使使用新工具更新创建的项目,我似乎也无法将其正确发布到 Azure。

【问题讨论】:

  • 网关错误很可能意味着您的应用程序根本没有启动。在将应用程序部署到 Azure 之前如何发布它?发布应用程序后,您的 web.config 看起来如何?我认为发生的事情是您的 web.config 只有占位符值。开箱即用的应用程序设置为在发布应用程序以修复您的配置后运行 publish-iis 工具。我认为要么这一步没有发生,要么 - 如果你从 RC1 移动到 RC2 - web.config 不在正确的位置,因为它现在应该在 approot 而不是 wwwroot。
  • 我们在 CI 上有一个脚本,它运行 dotnet restore、dotnet build 和 dotnet publish 到一个位置,然后我们使用文章中提到的 repo 中的 vs publish 脚本来执行实际操作天蓝色部署。这个项目从一开始就一直是 RC2 webconfig 是您通过新的 VS 工具更新启动一个新的 RC2 项目时获得的默认配置。 web.config 位于启动.cs 和 program.cs 旁边的 approot 中。
  • 我写了一篇关于使用 IIS 运行 ASP.NET Core 应用程序的帖子,其中包含有关 502.3 Bad Gatway 故障排除的整个部分:blog.3d-logic.com/2016/06/08/…。您可能会发现它很有帮助。

标签: powershell azure asp.net-core


【解决方案1】:

你有 web.config 吗?它是否像这样包含在您的 project.json 中:

"publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  }

您的 web.config 将如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" 
           resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" 
                stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"  
                forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>

注意:环境变量 LAUNCHER_PATH 和 LAUNCHER_ARGS 可能是问题的根源。您正在尝试启动 Visual Studio 运行的发布脚本,可能是 Visual Studio 在运行脚本之前设置了环境中的值。

要在 Azure VM 上启动并运行 RC2 站点,我必须将该行更改为如下所示:

<aspNetCore processPath="dotnet" arguments="./YourAppEntryPoint.dll" 
            stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" 
            forwardWindowsAuthToken="false"/>

尝试使用显式值设置您的 web.config。如果您的部署有效,那么您就知道是缺少的 ENVVARS 搞砸了。

【讨论】:

  • publish-iis 工具应该是wired as a postpublish script,它会相应地为您修复配置。
  • 仅当您使用 Visual Studio 时。
  • 不,您可以自己设置。 publish-iis 不是 VS 工具,是通用工具。
猜你喜欢
  • 2016-05-20
  • 1970-01-01
  • 1970-01-01
  • 2019-05-25
  • 1970-01-01
  • 2021-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多