.NET Core 发布到 IIS - HTTP 错误 502.3 - 错误网关 - 指定的 CGI 应用程序遇到错误并且服务器终止了该进程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39756042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.NET Core publish to IIS - HTTP Error 502.3 - Bad Gateway - The specified CGI application encountered an error and the server terminated the process
提问by John-Luke Laue
I'm trying to publish to IIS a .NET Core ASP.NET Website I upgraded from RC2 to RTM.
我正在尝试将我从 RC2 升级到 RTM 的 .NET Core ASP.NET 网站发布到 IIS。
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.
作为完整性检查,我成功地从 Visual Studio 2015 发布了模板/示例“ASP.NET Core Web 应用程序(.NET Framework)”应用程序。
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.
但是由于某种原因,在发布 RTM 升级的应用程序时,我收到HTTP 错误 502.3 - 错误网关指定的 CGI 应用程序遇到错误,服务器终止了该进程。
The site DOES work running IIS Express from Visual Studio.
该站点可以从 Visual Studio 运行 IIS Express。
How can I debug this? Anyone have any ideas?
我该如何调试?谁有想法?
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
项目.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"
]
]
}
}
采纳答案by Shaun Luttin
How can I debug this? Anyone have any ideas?
我该如何调试?谁有想法?
Here are three ideas:
这里有三个想法:
Read thisand make sure that you have covered all that it says.
Run the published
.\MyApp.exefrom 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.
Change
stdoutLogEnabled="false"totrueand then check the logs atstdoutLogFile=".\logs\stdout". The error(s) there might tell you something.Check your IIS Application logs in the Event Viewer. The error(s) there might tell you something.
阅读本文并确保您已涵盖所有内容。
.\MyApp.exe从命令行运行已发布。那样有用吗?- 如果是这样,您就知道存在 IIS 集成问题。
- 如果没有,您就知道您遇到了应用程序问题。
更改
stdoutLogEnabled="false"为true,然后检查日志stdoutLogFile=".\logs\stdout"。那里的错误可能会告诉你一些事情。在事件查看器中检查您的 IIS 应用程序日志。那里的错误可能会告诉你一些事情。
Event Viewer Application Logs
事件查看器应用程序日志
回答by zmHyman
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'.
如果您长时间运行任务,并且 Web 浏览器在 2 分钟(默认请求时间)内没有收到响应,您将收到此错误。因为超时后,IIS 将替换应用程序以'Bad Gateway' 响应客户端。
Maybe you should change the request time in the web.config.
也许您应该在 web.config 中更改请求时间。
Set requestTimeoutattribute in section system.webServer / aspNetCoreto specifies the duration for which the ASP.NET Core Module will wait for a response from the process listening on %ASPNETCORE_PORT%.
在system.webServer / aspNetCore部分中设置requestTimeout属性以指定 ASP.NET Core 模块等待来自侦听 %ASPNETCORE_PORT% 的进程的响应的持续时间。
- The requestTimeoutmust be specified in whole minutes only, otherwise it defaults to 2 minutes.
- 在将requestTimeout必须仅整个分钟来指定,否则默认为2分钟。
Just like this:
像这样:
<system.webServer>
<aspNetCore requestTimeout="00:20:00" ... />
</system.webServer>
回答by Rouhollah Torshizi
The solutions did not work for me, but what did is:
解决方案对我不起作用,但所做的是:
Enable web developer mode (press F12 in your browser)=> application tab =>then remove all cookies. Refresh the page and voilà: it works. Also you can copy your URL and paste to another browser you haven't run any MVC project.
启用 Web 开发人员模式(在浏览器中按 F12)=> 应用程序选项卡 => 然后删除所有 cookie。刷新页面,瞧:它有效。您也可以复制您的 URL 并粘贴到您尚未运行任何 MVC 项目的另一个浏览器。
My project worked on Internet Explorer and Microsoft Edge without any change. Perhaps that's the cause of your error.
我的项目在 Internet Explorer 和 Microsoft Edge 上运行,没有任何更改。也许这就是你出错的原因。
回答by Graham Meehan
Not directly an answer to the OP's specific instance of this 502.3 error, but it also can occur if there is an infinite loop, as I accidentally left in my application:
不是直接回答这个 502.3 错误的 OP 特定实例,但如果存在无限循环,它也可能发生,因为我不小心留在了我的应用程序中:
public class Category
{
public Category()
{
ParentCategory = new Category();
}
Category ParentCategory { get; set; }
}
There was no clear error indicating that this was the issue. Hope it helps someone.
没有明显的错误表明这是问题所在。希望它可以帮助某人。


