无法访问在ec2上运行的dot net core应用程序

时间:2017-02-07 16:25:04

标签: c# .net amazon-ec2 .net-core kestrel-http-server

我在访问运行在Windows 2016服务器实例上的.netcore应用时出现问题。

project.json:

    {
  "dependencies": {
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "HtmlAgilityPack.NetCore": "1.5.0.1",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.1.0",
          "type": "platform"
        }
      }
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "outputName": "chromagram"
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },
  "runtimes": {
    "win10-x64": {}
  },
  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

Program.cs主要功能:

public class Program
{
    public static void Main(string[] args)
    {

        var host = new WebHostBuilder()
            .UseKestrel()
            .UseUrls("http://0.0.0.0:6000")
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
}

When I run the application it works fine.

When I try to access localhost:6000 on the server its running on, it works great.

但是当我尝试从端口6000上的任何其他机器连接到服务器时,我得不到任何响应。 (我已将端口6000上的入站请求添加到ec2安全组)

.UseUrls("http://0.0.0.0:6000")

这应该意味着它会监听所有网络接口,但它似乎不是。

1 个答案:

答案 0 :(得分:0)

我在EC2上也遇到了同样的问题,而Mike B的评论已解决。在AWS安全组中,为您的IP添加TCP端口6000(如果您不关心安全性,则添加0.0.0.0/0)。然后,在Windows Server EC2实例上,转到“控制面板”>“ Windows Defender Fire Wall”>“高级”。手动为“端口”>“ TCP”>“ 6000”添加入站规则。在另一台服务器上,尝试使用http://:6000访问您的dotnet核心应用程序,它应该可以工作。

相关问题