简体   繁体   English

如何将外部域绑定到 .NET Core 3.1 Kestrel 自托管应用程序?

[英]How to bind external domain to .NET Core 3.1 Kestrel self-hosted application?

I have a simple .NET Core 3.1 self-hosted Kestrel application.我有一个简单的 .NET Core 3.1 自托管 Kestrel 应用程序。 After publishing to my server, it runs correctly at http://localhost:5000 .发布到我的服务器后,它在http://localhost:5000正确运行。

I want to access this application via a remote browser, so I changed the Program.cs as below:我想通过远程浏览器访问这个应用程序,所以我更改了Program.cs如下:

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

    public static IHostBuilder CreateHostBuilder(string[] args) =>
    {
        Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.ConfigureKestrel(so =>
            {
                so.Listen(IPAddress.Any, 5000); //==> This is OK
            });
            webBuilder.UseStartup<Startup>();
        });
    }   
}

Now the application is reachable from any remote browser via http://IP:port address.现在可以通过http://IP:port地址从任何远程浏览器访问该应用程序。 Instead of using IP:Port, however, I want to bind a domain URL (for example www.XXXX.com ) to my application.但是,我不想使用 IP:Port,而是想将域 URL(例如www.XXXX.com )绑定到我的应用程序。

I use Cloudflare as my DNS and proxy server.我使用 Cloudflare 作为我的 DNS 和代理服务器。 Keep in mind that Cloudflare does not support port forwarding.请记住,Cloudflare 不支持端口转发。 Also, the Portzilla App in Cloudflare had no use for me.此外,Cloudflare 中的 Portzilla 应用程序对我没有用。

What I have done so far is I've added a new IP (let's say 112.250.22.33 ) to the server, and tried to configure the application to listen on port 80 of this specific IP address:到目前为止,我所做的是向服务器添加了一个新的 IP(比方说112.250.22.33 ),并尝试将应用程序配置为侦听此特定 IP 地址的端口 80:

webBuilder.ConfigureKestrel(so =>
{
    so.Listen(IPAddress.Parse("112.250.22.33"), 80); //==> NOT OK
});

With this configuration, however, the application does not run at all—even if I run it in Run as administrator mode.但是,使用此配置,应用程序根本无法运行——即使我以管理员身份运行它也是如此。 Instead, it returns with this error:相反,它返回此错误:

Microsoft.AspNetCore.Server.Kestrel[0] Unable to start Kestrel. Microsoft.AspNetCore.Server.Kestrel[0] 无法启动 Kestrel。 System.Net.Sockets.SocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions. System.Net.Sockets.SocketException (10013):尝试以访问权限禁止的方式访问套接字。

Any help will be appreciated.任何帮助将不胜感激。

I am not sure, but looks like 80 port is holding by IIS. I disabled DefaultWebSite and could bind domain name to local Kestrel run.我不确定,但看起来80端口由 IIS 持有。我禁用了DefaultWebSite并且可以将域名绑定到本地 Kestrel 运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自托管 Net Core 3 应用程序不采取端口设置 - Self-hosted Net Core 3 application does not take port settings 自托管 .NET 核心控制台应用程序中的 Startup.cs - Startup.cs in a self-hosted .NET Core Console Application 如何在自托管的.net核心mvc应用程序中运行长时间运行或重复运行的任务? - How should I run long-running or recurring taks in a self-hosted .net core mvc application? ASP.NET Core 3.1 Web API: can it be self-hosted as Windows service with https and use some certificate like IIS? - ASP.NET Core 3.1 Web API : can it be self-hosted as Windows service with https and use some certificate like IIS? 自托管进程中 Web API 带点网核心 - Self-hosted In Process Web API with Dot net core 如何在asp.net自托管API中启用CORS? - How to enable CORS in asp.net Self-Hosted API? 如何在自托管的WebAPI应用程序中正确缓存数据 - how to properly cache data in a self-hosted WebAPI application WCF“自托管”应用程序变得无法响应 - WCF “Self-Hosted” application becomes unresponsive .NET 6 中的自托管 Web API - Self-Hosted Web API in .NET 6 如何使用托管在 .Net framework 4.6 应用程序中的登录页面对 .Net Core 3.1 上的 IdentityServer4 应用程序进行身份验证? - How to use login page hosted in .Net framework 4.6 application to authenticate for IdentityServer4 application on .Net Core 3.1?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM