简体   繁体   English

无法将ASP.NET Core应用程序部署到IIS-错误的网关

[英]Unable to deploy ASP.NET Core app to IIS - Bad Gateway

Have been struggling to get this to work, I have a standard .NET Core API that I want to host on a remote IIS server, the issue is most of the tutorials are for ASP.NET 5/vNext and don't explain what happens once you run your dotnet publish . 一直在努力使其工作,我有一个标准的.NET Core API,我想在远程IIS服务器上托管,问题是大多数教程都是针对ASP.NET 5 / vNext的,并且不解释会发生什么情况一旦您运行dotnet publish My bindings are correct but I'm not sure if i'm pointing at the right folder. 我的装订是正确的,但是我不确定是否指向正确的文件夹。

In my output folder I have publish and wwwroot as well as config.json and some other json files. 在我的输出文件夹中,我有publishwwwroot以及config.json和其他一些json文件。 When I point IIS to the wwwroot folder I get: 当我将IIS指向wwwroot文件夹时,我得到:

502 - Web server received an invalid response while acting as a gateway or proxy server. 502-Web服务器在充当网关或代理服务器时收到无效响应。

I get 404s if I try point it to any other folder. 如果我尝试将其指向任何其他文件夹,则会得到404。 I have HttpPlatformHandler 1.2 installed. 我已经安装了HttpPlatformHandler 1.2。 My project.json is as follows: 我的project.json如下:

  {
  "compilationOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot"
    ]
  },

  "dependencies": {
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-*",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-*",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-*",
    "Microsoft.AspNetCore.Hosting": "1.0.0-*",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-*",
    "Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-*",
    "Microsoft.AspNetCore.Mvc": "1.0.0-*",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-*",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-*",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*",
    "Microsoft.Extensions.Logging.Console": "1.0.0-*",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-*",
    "OpenIddict.Core": "1.0.0-*",
    "OpenIddict.EF": "1.0.0-*",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002700"
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "portable-net45+wp80+win8+wpa81+dnxcore50",
        "portable-net451+win8"
      ]
    }
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-*",
      "imports": "portable-net45+wp80+win8+wpa81+dnxcore50"
    }
  },

  "scripts": {
    "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
  },

  "content": [
    "wwwroot",
    "config.json",
    "web.config"
  ],

  "exclude": [
    "wwwroot",
    "node_modules"
  ],

  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

I took elements of this sample for my project.json . 我将这个示例的元素用于我的project.json

I pointed IIS to the root folder to the application folder and NOT the wwwroot and it worked. 我将IIS指向应用程序文件夹的根文件夹,而不是wwwroot,它起作用了。

The IIS server needs to have DotNetCore.1.0.0.RC2-WindowsHosting.exe IIS服务器需要具有DotNetCore.1.0.0.RC2-WindowsHosting.exe

Your Physical path in IIS should point to the wwwroot folder from your publish output. 您在IIS中的物理路径应指向发布输出中的wwwroot文件夹。

在此处输入图片说明

The approot folder also needs to be placed in the same dir as the wwwroot folder. 还需要将approot文件夹放置在与wwwroot文件夹相同的目录中。

I've found it helpful to try running web.cmd in the approot folder and seeing if it'll start. 我发现尝试在approot文件夹中运行web.cmd并查看它是否会启动很有帮助。 It's easier to see the startup exceptions (if there are any) when running web.cmd. 运行web.cmd时,更容易看到启动异常(如果有)。 You can also change the stdoutLogEnabled flag in the wwwroot/web.config file to true to get any startup exceptions from IIS. 您还可以将wwwroot / web.config文件中的stdoutLogEnabled标志更改为true,以从IIS获取任何启动异常。

Finally, on at least one occasion, after hitting my head against a wall for an hour trying to get it working, I rebooted my IIS server and suddenly it was working correctly. 最终,至少有一次,我将头撞在墙上一个小时试图使其正常工作后,我重新启动了IIS服务器,突然它正常工作。 Obviously a last resort if it's a prod server 如果是产品服务器,显然是不得已的选择

I face the same issue on Windows 2012 R2 server when I deploy site on IIS; 当我在IIS上部署站点时,在Windows 2012 R2服务器上遇到相同的问题; bad gateway issue. 网关问题。 Yes, I was using .Net Core 2.0. 是的,我正在使用.Net Core 2.0。 On IIS I had application pool "No Managed Code"; 在IIS上,我有应用程序池“无托管代码”。 Managed pipeline "Integrated" and still had the same issue. 托管管道“集成”,仍然存在相同的问题。 Solution was install DotNetCore.2.0.0-WindowsHosting.exe on server and success :) 解决方法是在服务器上安装DotNetCore.2.0.0-WindowsHosting.exe并成功:)

What worked for me: when publishing to set Seld-Contained for Deployment Mode. 对我有用的方法:发布时将“部署模式”设置为“包含”。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM