无法启动Kestrel。 System.IO.IOException:无法绑定到地址http://127.0.0.1:5000:已在使用的地址

问题描述 投票:-1回答:1

我按照此URL中的步骤将.NET核心2.1 Web应用程序代码发布到Linux Centos 7服务器。

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.2

我试图运行“sudo dotnet application_name.dll”。我收到以下错误消息。我错过了什么吗?我在Windows机器上使用Visual Studio 2017发布代码并将代码复制到Linux服务器。

crit: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use ---> System.Net.Sockets.SocketException: Address already in use

Program.cs中

  public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }

Startup.cs配置

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

        app.UseForwardedHeaders(new ForwardedHeadersOptions
        {
            ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
        });
    }

launchSettings.json:

  "applicationUrl": "https://localhost:5001;http://localhost:5000"
linux asp.net-core .net-core centos7 asp.net-core-2.1
1个回答
1
投票

错误消息很明确:您的计算机上的某些内容已在侦听端口5000。

2解决方案:

  • 找到正在收听此端口的内容并将其停止。
  • 绑定到另一个端口。
© www.soinside.com 2019 - 2024. All rights reserved.