[英]Access linux-hosted ASP.NET Core 2.x webapp (without nginx)
My ASP.NET Core 2.1 webapp works perfectly on my dev setup. 我的ASP.NET Core 2.1 Webapp可以在我的开发设置上完美运行。 Now I want to test it in production.
现在,我想在生产中对其进行测试。
The production server is Ubuntu 18. I followed the instructions . 生产服务器是Ubuntu18。我按照说明进行操作 。 I don't want to setup nginx yet, just do some quick tests, and the instructions say:
我现在还不想设置Nginx,只需进行一些快速测试,说明就会说:
"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".
“任何配置(带有或不带有反向代理服务器)都是ASP.NET Core 2.0或更高版本应用程序的有效且受支持的主机配置”。
So I built and published my project: dotnet publish --configuration Release
. 因此,我构建并发布了我的项目:
dotnet publish --configuration Release
。 Then on the server: 然后在服务器上:
/var/www/myapp
) /var/www/myapp
) sudo uwf allow 5000/tcp 80/tcp
sudo uwf allow 5000/tcp 80/tcp
dotnet MyApp.dll
(also tried sudo dotnet MyApp.dll
) dotnet MyApp.dll
(也尝试了sudo dotnet MyApp.dll
) It runs without errors/warnings, and says it's listening on http://localhost:5000
. 它运行时没有错误/警告,并表示它正在监听
http://localhost:5000
。
On my local machine I tried http://serveripaddress
(and http://serveripaddress:5000
) but get nothing ("can't connect"). 在我的本地计算机上,我尝试使用
http://serveripaddress
(和http://serveripaddress:5000
),但一无所获(“无法连接”)。 I can access that server with ssh, sftp, etc - only http isn't working. 我可以使用ssh,sftp等访问该服务器-只有http无法正常工作。
What am I doing wrong? 我究竟做错了什么?
Found the problem. 找到了问题。 I needed to use:
我需要使用:
sudo ASPNETCORE_URLS="http://0.0.0.0:5000" dotnet MyApp.dll
Then it logs Now listening on: http://0.0.0.0:5000
. 然后,它记录“
Now listening on: http://0.0.0.0:5000
。 And I can access that from a remote client. 而且我可以从远程客户端访问它。
the host default bind is 127.0.0.1 , so you can only access the app locally. 主机默认绑定是127.0.0.1,因此您只能在本地访问该应用程序。 if you want to access it from Network, please add
--urls
parameter. 如果要从网络访问它,请添加
--urls
参数。 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. 我使用的dotnet核心SDK是2.1.400版。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.