簡述
練習.Net Core 佈署(採Framework-dependent deployments)至Ubuntu 14.04環境。
Skill
環境
- Mac
- .Net Core 2.1
- Ubuntu 14.04
Ubuntu 實作
-
首先安裝 .Net Core SDK install .net core sdk to ubuntu 14.04
wget -q https://packages.microsoft.com/config/ubuntu/14.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get install apt-transport-https sudo apt-get update sudo apt-get install dotnet-sdk-2.1
- 確認安裝是否成功 (check dotnet)
dotnet --version
- 建立webapi專案 (create dotnet webapi project)
dotnet new webapi -o LeoAPI
- 切換至專案資料夾 (switch folder)
cd LeoAPI/
- 修改檔案 (modify file) Startup.cs
- 編輯檔案指令 (edit cmd)
nano Startup.cs
- 註解自動轉導https的設定 (mark https code)
// app.UseHttpsRedirection();
- 編輯檔案指令 (edit cmd)
- 修改專案的配置 (modify file) Properties/launchSettings.json
-
編輯檔案指令 (edit cmd)
nano Properties/launchSettings.json
-
將檔案裡的 localhost 改為 127.0.0.1
"applicationUrl": "https://127.0.0.1:5001;http://127.0.0.1:5000"
-
- 建置專案 (build project)
dotnet build
-
執行專案 (run project)
dotnet run
- 建立發佈資料夾 (create publish folder)
mkdir /var/dotnetcore
-
執行發佈指令至指定資料夾 (dotnet publish to publish folder)
dotnet publish /LeoAPI/LeoAPI.csproj -c Release -o /var/dotnetcore/
-
瀏覽發佈資料夾 (view publish folder)
ls /var/dotnetcore/
- 安裝 (install) supervisor
sudo apt-get install supervisor
-
建立 (create) leoapi.conf
nano /etc/supervisor/conf.d/leoapi.conf
[program:leoapi] command=/usr/bin/dotnet /var/dotnetcore/LeoAPI.dll directory=/var/dotnetcore/ autostart=true autorestart=true stderr_logfile=/var/log/leoapi.err.log stdout_logfile=/var/log/leoapiout.log environment=HOME=/var/www/,ASPNETCORE_ENVIRONMENT=Production user=www-data stopsignal=INT stopasgroup=true killasgroup=true
- 啟動服務 (start service)
sudo service supervisor start
-
測試 (test) API
curl http://127.0.0.1:5000/api/values
- 停止服務 (stop service)
sudo service supervisor stop