1.linux安裝 ASP.NET Core 5.0運行時,用sudo dnf install aspnetcore-runtime-5.0命令進行安裝,安裝完成后,通過 sudo dotnet --info 驗證是否安裝成功。
2.用FolderProfile(文件)發布asp.net core 5.0的webapi程序,目標框架是net5.0,目標運行時選中linux-x64,進行保存並發布
3.將發布后的文件夾進行打包,打包成rar格式,並利用MobaXterm上傳該壓縮包至連接的linux的文件中,創建一個net文件夾並進入該目錄,利用命令 rar x WebApiDemo.rar 進行解壓縮解壓縮。
4.執行dotnet WebApiDemo.dll --urls http://*:5000命令,出現以下提示說明webapi服務已經運行,訪問http://localhost:5000即可。
5.若提示404,上圖最后一行提示Failed to determine the https port for redirect,說明創建的webapi項目配置了https,只要注釋掉Startup中的app.UseHttpsRedirection();以及刪除launchSetting.json中的https://localhost:5001
6.若用其他終端訪問改端口,需要暴露linux的端口。
firewall-cmd --zone=public --add-port=5000/tcp --permanent 開啟端口外網訪問
firewall-cmd --reload 更新防火牆規則