Accessing .net Core API via azure VM throws ERR_CONNECTION_REFUSED

不羁岁月 提交于 2021-02-10 14:40:43

问题


I've set up a linux VM using Azure and I have the public IP from that machine.

I've cloned my repo inside that machine and I run dotnet run and I get the output:

Hosting environment: Development
Content root path: /home/g67Admin/projeto_integrador_grupo67/mdv
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

Then I try to go to: https://(public IP):5001/api/Drivers and I cannot access it, gives me this error ERR_CONNECTION_REFUSED.

I've went to the azure portal and tried to authorize the ports 5000 and 5001 from any source to any source, rebooted the machine multiple times and still get connection refused.

How can I solve this?


回答1:


By default, your local development server won't listen on your public IP or allow traffic from any other machine in your network. It only listens on localhost. You need to explicitly bind other urls to your server.

https://weblog.west-wind.com/posts/2016/sep/28/external-network-access-to-kestrel-and-iis-express-in-aspnet-core

You can run your code like this:

dotnet run --urls http://0.0.0.0:5001

Or you can use Use WebHost.UseUrls() to achieve a similar result.



来源:https://stackoverflow.com/questions/65469631/accessing-net-core-api-via-azure-vm-throws-err-connection-refused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!