首页 > 代码库 > linux+asp.net core+nginx+sql server

linux+asp.net core+nginx+sql server

Linux Disibutaion:Ubuntu 16.04.1 LTS

Web Server:Nginx、Kestrel

  • 安装.net core
sudo sh -c ‘echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list‘sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893sudo apt-get update#Install .NET Core SDK#由于我本地VS安装的.Net Core版本为:dotnet-dev-1.0.0-preview2-003131,所以在linux中安装的.Net Core需要保持一致sudo apt-get install dotnet-dev-1.0.0-preview2-003131

  

  • 安装npm,gulp,bower
sudo apt-get install npmsudo npm install gulp -gsudo npm install bower -g

  

  • 安装nginx
#安装nginxsudo apt-get install nginx -y#启动nginxsudo service nginx start

  因为要使用nginx做asp.net core网站的反向代理,我们需要修改nginx的默认配置文件/etc/nginx/sites-available/default ,将以下内容替换默认配置:

server {    listen 80;    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配置是否zhengquesudo nginx -t#重新加载nginx配置sudo nginx -s reload

  

  • 安装supervisor

  我们部署的网站并不会自己启动并运行,这里我们就需要用到supervisor这个工具,保证网站的启动和持续运行。

#安装supervisorsudo apt-get install supervisor

  配置supervisor,进入目录(/etc/supervisor/conf.d/),新建配置文件hwapp.conf,将如下内容复制到文件中

[program:hwapp]command=/usr/bin/dotnet /var/hwapp/hwapp.dll --server.urls:http://*:5000directory=/var/hwappautostart=trueautorestart=truestderr_logfile=/var/log/hwapp.err.logstdout_logfile=/var/log/hwapp.out.logenvironment=ASPNETCORE_ENVIRONMENT=Productionuser=www-datastopsignal=INT

  启动supervisor

sudo service supervisor start

  

  • 安装sql server

  Import the public repository GPG keys:

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

  注册Microsoft SQL Server Ubuntu存储库:

curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server.list | sudo tee /etc/apt/sources.list.d/mssql-server.list

  安装SQL Server

sudo apt-get updatesudo apt-get install -y mssql-server

  配置SQL Server

sudo /opt/mssql/bin/sqlservr-setup

  验证SQL Server是否启动

systemctl status mssql-server

  安装sqlcmd工具

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.listsudo apt-get update sudo apt-get install mssql-tools

  到此,我们的环境都准备好了,可以在linux上操作SQL Server

技术分享

我这里在本地VS写了一个asp.net core的demo,去操作安装在linux上的sqlserver。

技术分享

上图首页上的数据就是从数据库中取出的,见下图:

技术分享

 源码下载

linux+asp.net core+nginx+sql server