Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access linux-hosted ASP.NET Core 2.x webapp (without nginx)

My ASP.NET Core 2.1 webapp works perfectly on my dev setup. Now I want to test it in production.

The production server is Ubuntu 18. I followed the instructions. I don't want to setup nginx yet, just do some quick tests, and the instructions say:

"Either configuration—with or without a reverse proxy server—is a valid and supported hosting configuration for ASP.NET Core 2.0 or later apps".

So I built and published my project: dotnet publish --configuration Release. Then on the server:

  • install the dotnet runtime
  • copied files to server (/var/www/myapp)
  • opened ports: sudo uwf allow 5000/tcp 80/tcp
  • run dotnet MyApp.dll (also tried sudo dotnet MyApp.dll)

It runs without errors/warnings, and says it's listening on http://localhost:5000.

On my local machine I tried http://serveripaddress (and http://serveripaddress:5000) but get nothing ("can't connect"). I can access that server with ssh, sftp, etc - only http isn't working.

What am I doing wrong?

like image 931
lonix Avatar asked Mar 02 '26 02:03

lonix


1 Answers

the host default bind is 127.0.0.1 , so you can only access the app locally. if you want to access it from Network, please add --urls parameter. for example :

for development, you can run:

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

and for deployed project, you can run:

dotnet MyApp.dll --urls http://0.0.0.0:5000

The dotnet core sdk I use is version 2.1.400.

like image 113
zhimin Avatar answered Mar 04 '26 20:03

zhimin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!