在CentOS8中部署Asp.net Core 5.0 WebApi

1.linux安裝 ASP.NET Core 5.0運行時,用sudo dnf install aspnetcore-runtime-5.0命令進行安裝,安裝完成後,經過 sudo dotnet --info 驗證是否安裝成功。linux

2.用FolderProfile(文件)發佈asp.net core 5.0的webapi程序,目標框架是net5.0,目標運行時選中linux-x64,進行保存併發布web

 

3.將發佈後的文件夾進行打包,打包成rar格式,並利用MobaXterm上傳該壓縮包至鏈接的linux的文件中,建立一個net文件夾並進入該目錄,利用命令 rar x WebApiDemo.rar 進行解壓縮解壓縮。json

4.執行dotnet WebApiDemo.dll --urls http://*:5000命令,出現如下提示說明webapi服務已經運行,訪問http://localhost:5000便可。api

 

 

 5.若提示404,上圖最後一行提示Failed to determine the https port for redirect,說明建立的webapi項目配置了https,只要註釋掉Startup中的app.UseHttpsRedirection();以及刪除launchSetting.json中的https://localhost:5001併發

 

 6.若用其餘終端訪問改端口,須要暴露linux的端口。app

 

 

 firewall-cmd --zone=public --add-port=5000/tcp --permanent    開啓端口外網訪問框架

firewall-cmd --reload    更新防火牆規則asp.net

 

 

 

相關文章
相關標籤/搜索