简体   繁体   English

无法从服务器外部访问linux上的asp.net核心mvc应用程序

[英]asp.net core mvc app on linux can't be reached from outside the server

It's an asp.net core 2.1 mvc application hosted on an ubuntu 18.04 with Nginx. 它是一个asp.net核心2.1 mvc应用程序,托管在带有Nginx的ubuntu 18.04上。 UFW is disabled. UFW已禁用。 The web application was working in the beginning. Web应用程序一开始就在工作。 When I found out it's down it has been some time. 当我发现它已经失效时,它已经有一段时间了。

Using a browser I go to thesite.com, the browser was redirected to https://www.thesite.com:5001/ with error: 使用浏览器我访问site.com,浏览器被重定向到https://www.thesite.com:5001/ ,但错误:

This site can't be reached 无法访问此网站

ERR_CONNECTION_TIMED_OUT ERR_CONNECTION_TIMED_OUT

The port number was attached so it seems at least an outside request can reach Nginx. 端口号已附加,因此看起来至少外部请求可以到达Nginx。 Then inside the box when I ran 我跑的时候在盒子里面

wget https://localhost --no-check-certificate

I could get index.html which is the correct response. 我可以得到index.html这是正确的答案。 So it seems to me the web application is taking https requests. 所以在我看来,Web应用程序正在接受https请求。

I have never changed default listening port, to verify, I ran this to check listening ports 我从来没有更改过默认监听端口,要验证,我运行这个来检查监听端口

sudo netstat -tnlp | grep :5001

The result shows dotnet is listening on port 5001 and 5000. 结果显示dotnet正在侦听端口5001和5000。

In another attempt, I used visual studio debugger to attach to the linux dotnet process, and set a few breakpoints. 在另一次尝试中,我使用visual studio调试器连接到linux dotnet进程,并设置了几个断点。 I could see that when using a browser the breakpoint was not reached. 我可以看到,当使用浏览器时,未达到断点。 But when using wget like above the breakpoint was reached. 但是当使用上面的wget时,达到了断点。

Any advice is appreciated. 任何建议表示赞赏。 Thank you. 谢谢。

Well, I changed two things in /etc/nginx/sites-enabled/www.thesite.com file, and the web app is online again. 好吧,我在/etc/nginx/sites-enabled/www.thesite.com文件中更改了两件事,并且Web应用程序再次在线。

  1. In the Location section, change bypass_proxy line, from http to https 在“位置”部分中,将bypass_proxy行从http更改为https

  2. In upstream section, change "server 127.0.0.1:5000;" 在上游部分,更改"server 127.0.0.1:5000;" to "server 127.0.0.1:5001;" "server 127.0.0.1:5001;"

That solved the problem. 这解决了这个问题。 Although I don't know why. 虽然我不知道为什么。

Also, I figured out how long the web app has been down, it was only one day. 此外,我想出了网络应用程序停机了多长时间,只有一天。 Because another service that was making use of the web app was working fine until the day before. 因为使用网络应用程序的另一项服务工作正常,直到前一天。 I don't know why the nginx config file quit working without any change. 我不知道为什么nginx配置文件退出工作没有任何改变。 I guess this is a special case, hopefully, it can help someone. 我想这是一个特例,希望它可以帮助某人。

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

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