通过PowerShell将Azure Core应用程序发布到Azure,在Azure中获取502(Bad Gateway)

时间:2022-10-15 03:31:49

How can I publish my ASP.NET Core application to Azure?

如何将ASP.NET核心应用程序发布到Azure?

What I have done so far is created a script that I got from official Azure/Microsoft documents that call on default-publish.ps1 script that Visual Studio also uses. The script looks as follows:

到目前为止我所做的是创建了一个脚本,我从官方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

Now this script calls upon the default-publish.ps1 script, given you provide the Azure website name and the dotnet publish artifact. I have updated my default-publish.ps1 script to exactly what is currently in the repo.

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

The issue is that when I publish to Azure a 502 Bad Gateway error is returned. Even with a project created using the new tooling update, I cannot seem to publish it to Azure correctly.

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

1 个解决方案

#1


1  

Do you have a web.config? Is it included in your project.json like this:

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

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

Your web.config will look something like this:

你的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>

Note: The environment variables LAUNCHER_PATH and LAUNCHER_ARGS may be the source of your issue. You are attempting to launch the publishing scripts that visual studio runs, it is possible that visual studio sets the values in the environment before running the scripts.

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

To get an RC2 site up and running on an Azure VM, I had to change that line to look like this:

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

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

Try setting your web.config with the explicit values. If your deploy works, then you know it's the missing ENVVARS that are messing it up.

尝试使用显式值设置web.config。如果您的部署有效,那么您就知道正在丢失的ENVVARS正在弄乱它。

#1


1  

Do you have a web.config? Is it included in your project.json like this:

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

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

Your web.config will look something like this:

你的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>

Note: The environment variables LAUNCHER_PATH and LAUNCHER_ARGS may be the source of your issue. You are attempting to launch the publishing scripts that visual studio runs, it is possible that visual studio sets the values in the environment before running the scripts.

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

To get an RC2 site up and running on an Azure VM, I had to change that line to look like this:

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

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

Try setting your web.config with the explicit values. If your deploy works, then you know it's the missing ENVVARS that are messing it up.

尝试使用显式值设置web.config。如果您的部署有效,那么您就知道正在丢失的ENVVARS正在弄乱它。