[英]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.