ubuntu上部署windows開發的dotnet core程序

目標:完成windows上開發的dotnet core程序部署至linux服務器上(Ubuntu 14.04)html

windows上開發dotnet core很簡單,安裝好VS2017,創建相關類型的項目進行開發便可。linux

Linux服務器中須要作如下幾個工做:nginx

1.安裝dotnet core, 運行dotnet程序必備條件。web

2.安裝supervisor守護進程,能夠幫助你自動啓動站點。ubuntu

3.安裝nginx作代理windows

1. 安裝dotnet core服務器

#依次執行下面的命令,安裝的版本有問題的話,按照錯誤提示修改版本號便可
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ yakkety main" > /etc/apt/sources.list.d/dotnetdev.list'

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893

sudo apt-get update

sudo apt-get install dotnet-dev-2.0.1 

windows中的項目使用下面的命令行打包部署。須要在項目的項目文件(CoreApp.csproj)文件上增長一個配置節點。app

dotnet publish --framework netcoreapp2.1 --runtime ubuntu.14.04-x64 --output "E:\Publish\CoreApp" --configuration Release

須要增長的配置節點spa

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<!--增減對linux支持-->
<RuntimeIdentifiers>ubuntu.14.04-x64</RuntimeIdentifiers>
</PropertyGroup>

將部署包複製到linux服務器上,記住目錄,在supervisor配置文件中須要使用到這個目錄。.net

2.supervisor守護進程。dotnet core程序在Linux上,每次都須要dotnet run一下,若是遇到服務器重啓或者站點掛了須要重啓,就每次都要本身手動敲一下dotnet run命令。安裝這個守護進程,讓他幫忙監控,一但發現相應的站點不在運行了,就自動幫你執行啓動命令。 

//安裝
sudo apt-get install supervisor

//新建
touch CoreApp.conf //CoreApp.conf 添加以下內容 [program:CoreApp] command=dotnet CoreApp.dll directory=/home/gxwang/publish environment=ASPNETCORE__ENVIRONMENT=Production user=www-data stopsignal=INT autostart=true autorestart=true startsecs=1 stderr_logfile=/var/log/CoreApp.err.log stdout_logfile=/var/log/CoreApp.out.log 

//從新加載配置
sudo supervisorctl shutdown && sudo supervisord -c /etc/supervisor/supervisord.conf
//或重啓supervisor
sudo service supervisor stop
sudo service supervisor start

 supervisor開啓web端管理,在/etc/supervisor 目錄下,打開supervisor.conf 文件,添加以下配置項。

[inet_http_server]         ;HTTP服務器,提供web管理界面
port=127.0.0.1:9001        ;訪問方式IP+端口
username=admin             ;登陸時須要身份驗證的話,添加用戶名和密碼
password=admin123               

 

3.nginx

修改nginx配置,

sudo vi /etc/nginx/sites-available/default
#default配置文件下,增長一個虛擬主機,能夠使用同一臺機器監聽不一樣端口
# another virtual host using mix of IP-, name-, and port-based configuration # server { listen 81; # listen somename:8080; # server_name somename alias another.alias; # root html; # index index.html index.htm; # location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }

 

重啓nginx

sudo nginx -t
sudo nginx -s reload
相關文章
相關標籤/搜索