游戏技术文章

ASP.NET Core 发布至Linux生产环境 Ubuntu 系统

时间:2017-3-2 8:41:44  作者:棋牌资源网  来源:棋牌资源网  查看:7649  评论:0
内容摘要:ASP.NET Core 发布至Linux生产环境 Ubuntu 系统,之前跟大家讲解了 dotnet publish 发布,而没有将整个系统串起来。今天就跟大家综合的讲一下ASP.NET Core发布至Linux生产环境。 开发及发布环境:WIN10 x64 ...
ASP.NET Core 发布至Linux生产环境 Ubuntu 系统,之前跟大家讲解了 dotnet publish 发布,而没有将整个系统串起来。

今天就跟大家综合的讲一下ASP.NET Core发布至Linux生产环境。

 

开发及发布环境:WIN10 x64 

生产Linux环境:Ubuntu 14.04

 

发布的示例代码: https://github.com/linezero/NETCoreBBS

代码下载下来,首先请注释 Program.cs 中 .UseUrls("http://*:80")

ASP.NET_Core_发布至Linux生产环境_Ubuntu_系统

本篇将以发布dotnet publish两种方式做介绍。

默认发布

下载示例代码,定位到 src\NetCoreBBS 文件夹。

首先dotnet restore, 然后输入dotnet publish命令既可。

ASP.NET_Core_发布至Linux生产环境_Ubuntu_系统

 

自带运行时发布

定位到 src\NetCoreBBS 文件夹,打开 project.json 文件。

注释掉 "type": "platform" 

ASP.NET_Core_发布至Linux生产环境_Ubuntu_系统

首先同样 dotnet restore, 然后输入dotnet publish -r ubuntu.14.04-x64

ASP.NET_Core_发布至Linux生产环境_Ubuntu_系统

 

Ubuntu 配置

将刚才发布的文件夹分别上传至ubuntu系统,这里给大家推荐一个工具 WinSCP。

ASP.NET_Core_发布至Linux生产环境_Ubuntu_系统

对于默认发布,则使用, dotnet NetCoreBBS.dll 这里需要安装.NET Core SDK。

ASP.NET_Core_发布至Linux生产环境_Ubuntu_系统

对于自带运行时,设置权限,及安装对应依赖,无需安装SDK,直接使用 ./NetCoreBBS 运行。

设置权限: chmod -R 755 NetCoreBBS

ASP.NET_Core_发布至Linux生产环境_Ubuntu_系统

1.安装.NET Core SDK

https://www.microsoft.com/net/core#ubuntu

Ubuntu 14.04

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
sudo apt-get update
sudo apt-get install dotnet-dev-1.0.0-preview2-003121

安装好以后,就可以使用 dotnet 命令。

2.安装及配置Nginx

sudo apt-get install nginx

安装好以后,定位到 /etc/nginx/sites-available/default 文件。更改server 节点如下。

复制代码
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

sudo service nginx restart

 

3.安装及配置supervisor

sudo apt-get install supervisor

 

安装好 supervisor 以后,下面就来配置。

定位到 /etc/supervisor/conf.d/ 文件夹,添加一个NetCoreBBS.conf 文件。

下面是dotnet NetCoreBBS.dll 命令方式。经过多次的坑,终于得到最终配置文件。这里因为用到Sqlite 数据库,需要指定目录。

复制代码
[program:NetCoreBBS]
command=/usr/bin/dotnet /root/publish/NetCoreBBS.dll
directory=/root/publish
autostart=true
autorestart=true
stderr_logfile=/var/log/NetCoreBBS.err.log
stdout_logfile=/var/log/NetCoreBBS.out.log
environment=ASPNETCORE__ENVIRONMENT=Production
user=root
stopsignal=INT
复制代码

 

重启 supervisor,这里由于我放置在root 文件夹,所以需要root 用户,大家也可以放置在其他文件夹。

sudo service supervisor restart

 

下面是自带运行时方式,自带运行时可以省略掉第一步,无需安装SDK 安装几个依赖就行。可以参考之前文章:http://www.cnblogs.com/linezero/p/5475246.html

复制代码
[program:NetCoreBBS]
command=/root/publishself/NetCoreBBS
directory=/root/publishself
autostart=true
autorestart=true
stderr_logfile=/var/log/NetCoreBBS.err.log
stdout_logfile=/var/log/NetCoreBBS.out.log
environment=ASPNETCORE__ENVIRONMENT=Production
user=root
stopsignal=INT
复制代码

 

然后我们访问设置的ip 或者域名就能访问ASP.NET Core 站点了。

大家如果要配置多个站点,可以在Nginx 里进行配置。

 

参考文档:https://docs.asp.net/en/latest/publishing/linuxproduction.html

标签:ASP.NETCore发布至Linux生产环境Ubuntu系统 

欢迎加入VIP,【VIP售价:只要288元永久VIP会员】畅享商业棋牌游戏程序下载,点击开通!

下载说明


☉本站所有源码和资源均由站长亲自测试-绝对保证都可以架设,运营!
☉如源码和资源有损坏或所有链接均不能下载,请告知管理员,

☉本站软件和源码大部分为站长独资,资源购买和收集,放心下载!

☉唯一站长QQ:1004003180  [人格担保-本站注重诚信!]

☉购买建议E-mail:1004003180@qq.com   源码收购 E-mail:1004003180@qq.com    

☉本站文件解压密码  【文章内都自带解压密码,每个密码不同!】


本站提供的所有源码,均来源站长提供,仅学习交流 浙ICP备09009969号

由此产生不良后果和法律责任与本站无关,如果侵犯了您的版权,请来信告知 1004003180@qq.com 将及时更正和删除! 

Copyright © 2008-2024 棋牌资源网,你身边的棋牌资源下载站    All Rights Reserved