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

不想你离开。 提交于 2019-12-08 05:44:16

问题


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. 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. When I point IIS to the wwwroot folder I get:

502 - Web server received an invalid response while acting as a gateway or proxy server.

I get 404s if I try point it to any other folder. I have HttpPlatformHandler 1.2 installed. My project.json is as follows:

  {
  "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.


回答1:


I pointed IIS to the root folder to the application folder and NOT the wwwroot and it worked.

The IIS server needs to have DotNetCore.1.0.0.RC2-WindowsHosting.exe




回答2:


Your Physical path in IIS should point to the wwwroot folder from your publish output.

The approot folder also needs to be placed in the same dir as the wwwroot folder.

I've found it helpful to try running web.cmd in the approot folder and seeing if it'll start. It's easier to see the startup exceptions (if there are any) when running web.cmd. You can also change the stdoutLogEnabled flag in the wwwroot/web.config file to true to get any startup exceptions from 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. Obviously a last resort if it's a prod server




回答3:


I face the same issue on Windows 2012 R2 server when I deploy site on IIS; bad gateway issue. Yes, I was using .Net Core 2.0. On IIS I had application pool "No Managed Code"; Managed pipeline "Integrated" and still had the same issue. Solution was install DotNetCore.2.0.0-WindowsHosting.exe on server and success :)




回答4:


What worked for me: when publishing to set Seld-Contained for Deployment Mode.



来源:https://stackoverflow.com/questions/37256282/unable-to-deploy-asp-net-core-app-to-iis-bad-gateway

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!