简体   繁体   English

无法使用外部IP访问Nancy创建的主机

[英]Unable to access host created by Nancy using external IP

I am creating a Nancy Module that will eventually be hosted inside of a Windows Service. 我正在创建一个Nancy模块,该模块最终将托管在Windows Service中。 To start the Nancy hosting, I am using Nancy.Hosting.Self. 要启动Nancy托管,我正在使用Nancy.Hosting.Self。 Below is the code to start Nancy host. 下面是启动Nancy主机的代码。

string strHostProtocol = Convert.ToString(ConfigurationManager.AppSettings["HostProtocol"]);
string strHostIP = Convert.ToString(ConfigurationManager.AppSettings["HostIP"]);
string strHostPort = Convert.ToString(ConfigurationManager.AppSettings["HostPort"]);

//Here strHostProtocol="https", strHostIP = "192.168.100.88" i.e. System IPv4, strHostPort = "9003"

var url = strHostProtocol + "://" + strHostIP + ":" + strHostPort;
//url ="https://192.168.100.88:9003"

this.host = new NancyHost(new Uri(url));
this.host.Start();

Now once the windows service starts, it will start the above host and I could see this in netstat -a command. 现在,一旦Windows服务启动,它将启动上面的主机,我可以在netstat -a命令中看到它。 When I browse this in browser using https://192.168.100.88:9003 I will get proper response. 当我使用https://192.168.100.88:9003在浏览器中浏览时,我将得到正确的响应。

The problem arises when the same is browsed using its external IP. 使用其外部IP浏览相同内容时会出现问题。 Say this system has been assigned with external IP of 208.91.158.66 and when I try browsing this as https://208.91.158.66:9003 I will just get a browser default loading progress continuosly which does not stop and without any error thrown. 假设此系统已分配了208.91.158.66外部IP,当我尝试以https://208.91.158.66:9003浏览时,我将连续获得浏览器的默认加载进度,该进度不会停止并且不会引发任何错误。 I have also added the below command and reserved URL successfully. 我还成功添加了以下命令并保留了URL。

netsh http add urlacl url=https://192.168.100.88:9003/ user=everyone

But even after this the host cannot be browsed using external IP assigned to that system. 但是即使在此之后,也无法使用分配给该系统的外部IP浏览主机。 Is there any restricting Nancy is putting up? 南希有什么限制吗? Firewalls are turned off, defenders are turned off. 防火墙关闭,防御者关闭。 Anyone has any idea on this? 有人对此有任何想法吗?

UPDATE 更新

The duplicate linked question talks about LAN but here I am trying through external IP and I've tried answer mentioned over there and also specified the same in question 重复的链接问题是关于LAN的,但是我在这里尝试通过外部IP,并且尝试了在那儿提到的答案,并且还指定了相同的问题

Alright. 好的。 This issue was also posted to GitHub Nancy Repo and below is what @Khellang had to say. 这个问题也已经发布到GitHub Nancy Repo ,下面是@Khellang所说的。

When you bind to https://192.168.100.88:9003 , the TcpListener/HttpListener won't listen on other interfaces. 当您绑定到https://192.168.100.88:9003 ,TcpListener / HttpListener将不会在其他接口上进行监听。 You either have to bind to https://208.91.158.66:9003 or https://localhost:9003 and set RewriteLocalhost = true (default). 您必须绑定到https://208.91.158.66:9003https://localhost:9003并设置RewriteLocalhost = true(默认)。

Further he also said that 他还说

If you also want to listen to requests coming to the external IP, yes. 如果您还想监听来自外部IP的请求,可以。 Or you could use a wildcard, like https://+:9003/ , https://*:9003/ or https://localhost:9003/ (with RewriteLocalhost = true , this will result in https://+:9003/ ). 或者,您可以使用通配符,例如https://+:9003/https://*:9003/https://localhost:9003/ (如果RewriteLocalhost = true ,则结果为https://+:9003/ )。 You can read more about them in the link I posted. 您可以在我发布的链接中了解有关它们的更多信息。

and thanks to @TimBourguignon as he suggested the same in his comments. 还要感谢@TimBourguignon,因为他在评论中建议了相同的内容。 Hope this helps someone in future. 希望这对以后的人有所帮助。

He has also suggested to read this link to know more about the Strong Wildcard and Weak Wildcard 他还建议阅读this link以进一步了解Strong WildcardWeak Wildcard

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM