powershell - 通过 PowerShell 将 ASP.NET Core 应用程序发布到 Azure 在 Azure 中收到 502(错误网关)

标签 powershell azure asp.net-core

如何将 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。

最佳答案

你有 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 造成了困惑。

关于powershell - 通过 PowerShell 将 ASP.NET Core 应用程序发布到 Azure 在 Azure 中收到 502(错误网关),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37414657/

相关文章:

powershell - 使用 Powershell 将变量值传递到 Jenkins 文件中的不同本地范围

sql - Azure 在代码中创建数据库

Azure 移动服务 .net 后端添加 Facebook 登录范围

c# - Ubuntu 上 Dotnet Core 中的客户端证书

c# - 使用拥有的类型时,Entity Framework Core 尝试连接到不存在的表

powershell - 如何从 Powershell 中删除签名?

.net - win7或win2008如何使用Powershell自定义 "Region and Language"设置

azure - 注册具有应用程序权限的应用程序时 'supported account type'的重要性

c# - EF 核心 : Table "name" already exists - when trying to update database

html - powershell 可以用来点击 angularjs 按钮吗?