Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core publish to IIS - HTTP Error 502.3 - Bad Gateway - The specified CGI application encountered an error and the server terminated the process

I'm trying to publish to IIS a .NET Core ASP.NET Website I upgraded from RC2 to RTM.

As a sanity check, I was successfully able to publish the template/sample "ASP.NET Core Web Application (.NET Framework)" app from Visual Studio 2015.

But for some reason, when publishing the RTM upgraded app, I'm getting HTTP Error 502.3 - Bad Gateway The specified CGI application encountered an error and the server terminated the process.

The site DOES work running IIS Express from Visual Studio.

How can I debug this? Anyone have any ideas?

Error 502.3

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=".\MyApp.exe" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />   </system.webServer> </configuration> 

project.json

{   "buildOptions": {   "emitEntryPoint": true,   "preserveCompilationContext": true,   "warningsAsErrors": true }, "dependencies": {   "Microsoft.AspNetCore.Diagnostics.Elm": "0.1.0",   "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",   "Microsoft.AspNetCore.Authorization": "1.0.0",   "Microsoft.AspNetCore.Diagnostics": "1.0.0",   "Microsoft.AspNetCore.Hosting": "1.0.0",   "Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0",   "Microsoft.AspNetCore.Http.Extensions": "1.0.0",   "Microsoft.AspNetCore.Localization": "1.0.0",   "Microsoft.AspNetCore.Mvc": "1.0.0",   "Microsoft.AspNetCore.Routing": "1.0.0",   "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",   "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",   "Microsoft.AspNetCore.Session": "1.0.0",   "Microsoft.AspNetCore.StaticFiles": "1.0.0",   "Microsoft.Extensions.Caching.SqlServer": "1.0.0",   "Microsoft.Extensions.Logging.Console": "1.0.0",   "Microsoft.Extensions.Logging.Debug": "1.0.0",   "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",    "Microsoft.AspNetCore.Razor.Tools": {     "version": "1.0.0-preview2-final",     "type": "build"   },    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",   "Microsoft.Extensions.Configuration.Json": "1.0.0",   "Microsoft.Extensions.Logging": "1.0.0",   "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0" },  "frameworks": {    "net461": {}  },  "tools": {   "BundlerMinifier.Core": "2.0.238",   "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",   "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" },  "scripts": {   "prepublish": [ "bower install", "dotnet bundle" ],   "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" },  "publishOptions": {   "include": [     "wwwroot",     "web.config",     "appsettings.json",     "**/*.cshtml",     "Config/*.json"     ]   ]  } } 
like image 976
John-Luke Laue Avatar asked Sep 28 '16 19:09

John-Luke Laue


People also ask

What is 502 Bad Gateway error mean?

The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server.

When a proxy or gateway was unable to send the request to a parent gateway?

This error occurs when a CGI application does not return a valid set of HTTP headers, or when a proxy or gateway was unable to send the request to a parent gateway. You may need to get a network trace or contact the proxy server administrator, if it is not a CGI problem.


2 Answers

If you run a task for a long time, and web browser don't receives response in 2 mins(the default request time), you'll get this error. Because after the timeout, IIS will replaces the application to respond to the client with 'Bad Gateway'.

Maybe you should change the request time in the web.config.

Set requestTimeout attribute in section system.webServer / aspNetCore to specifies the duration for which the ASP.NET Core Module will wait for a response from the process listening on %ASPNETCORE_PORT%.

  • The requestTimeout must be specified in whole minutes only, otherwise it defaults to 2 minutes.

Just like this:

<system.webServer>   <aspNetCore requestTimeout="00:20:00" ... /> </system.webServer> 
like image 82
zmjack Avatar answered Sep 28 '22 02:09

zmjack


How can I debug this? Anyone have any ideas?

Here are three ideas:

  1. Read this and make sure that you have covered all that it says.

  2. Run the published .\MyApp.exe from the command line. Does that work?

    • If it does, you know you have an IIS integration problem.
    • If it does not, you know you have an application problem.
  3. Change stdoutLogEnabled="false" to true and then check the logs at stdoutLogFile=".\logs\stdout". The error(s) there might tell you something.

  4. Check your IIS Application logs in the Event Viewer. The error(s) there might tell you something.

Event Viewer Application Logs

Event Viewer Application Logs

like image 30
Shaun Luttin Avatar answered Sep 28 '22 00:09

Shaun Luttin