如何从公共互联网访问HTTP端口5001 [英] How to access HTTP port 5001 from public internet

查看:715
本文介绍了如何从公共互联网访问HTTP端口5001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Windows Server 2016数据中心x64,.NET Core SDK 5.0预览版,Microsoft SQL Server 2019

I have Windows Server 2016 Data center x64, .NET Core SDK 5.0 preview, Microsoft SQL Server 2019

在服务器上:https://localhost:5001/publisher/一切正常

On server: https://localhost:5001/publisher/all ok

在服务器 https://127.0.0.1:5001/publisher/all 好的

在服务器上:防火墙开放端口5000-6000出站

On server: Firewall Open port 5000-6000 outbound

从我的计算机(或世界上任何一台PC)上 https://45.118.145.72:5011/发布者/全部不正确

from my computer (or any PC on the world) https://45.118.145.72:5011/publisher/all not ok

如何从中访问 https://45.118.145.72:5011/publisher/all 公共互联网?

How to access https://45.118.145.72:5011/publisher/all from public internet?

推荐答案

Asp.NET核心应用程序绑定到本地主机".具有默认设置的网络接口.该网络接口无法从其他主机使用.

Asp.NET core apps bind to the "localhost" network interface with default settings. This network interface is not available from other hosts.

您可以在主机设置过程中使用UseUrls()进行修改.

You can modify this using UseUrls()during host setup.

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
            webBuilder.UseUrls("http://0.0.0.0:5001");
        });

示例:

webBuilder.UseUrls("http://127.0.0.1:5001"); // only from localhost
webBuilder.UseUrls("http://localhost:5001"); // only from localhost
webBuilder.UseUrls("http://0.0.0.0:5001");   // allow all hosts

文档: https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#kestrel-in-aspnet-core-apps

这篇关于如何从公共互联网访问HTTP端口5001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆