在Linux上部署.net core 2.0程序:

第一步:配置Nginx代理

在/etc/nginx/sites-available/default 中添加

server {
listen ;
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;
}
}

这样,访问80端口,就可以直接访问到localhost:5000端口了

第二步:如果一台服务器里要运行多个站点,就要配置Nginx 按照域名转发

server {
listen ;
server_name test1.api.com;
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;
}
} server {
listen ;
server_name test2.api.com;
location /{
proxy_pass http://localhost:5001;
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;
}
}

这样的话,通过域名 test1.api.com:80 访问就是localhost:5000的站点,通过域名test2.api.com:80 访问的就是localhost:5001的站点

/etc/nginx/nginx.conf 中的http{}中加入:

 include /etc/nginx/sites-enabled/*;

测试新增的配置是否正确

nginx -t

重新加载配置

nginx -s reload

第三步:设置守护进程

设置守护进程有很多方法,这里介绍利用Linux中的系统服务管理工具 Systemctl 。也是很方便的。

在/etc/systemd/system/ 文件夹下,新建一个test.service

[Unit]
Description = CNBlogs.ZzkService running on Ubuntu [Service]
WorkingDirectory = /test
ExecStart =/usr/bin/dotnet /test/bin/Debug/netcoreapp2./CNBlogs.ZzkService.WebApi.dll
Restart = always
RestartSec =
SyslogIdentifier = dotnet-example
User = root
Environment = ASPNETCORE_ENVIRONMENT=Production Environment = DOTNET_PRINT_TELEMETRY_MESSAGE=false

ExecStart 是运行命令

RestartSec 是每3秒检查一次

启动服务

systemctl enable test.service
systemctl start test.service

查看服务运行状态

systemctl status test.service

会出现类似下面的状态,表示运行正确:

● kestrel-hellomvc.service - Example .NET Web API Application running on Ubuntu
Loaded: loaded (/etc/systemd/system/kestrel-hellomvc.service; enabled)
Active: active (running) since Thu -- :: NZDT; 35s ago
Main PID: (dotnet)
CGroup: /system.slice/kestrel-hellomvc.service
└─ /usr/local/bin/dotnet /var/aspnetcore/hellomvc/hellomvc.dll

把Asp.Net Core 2.0部署在Linux上,使用Nginx代理服务器,并且用Systemctl命令以服务的方式监听项目的更多相关文章

  1. 翻译 - ASP.NET Core 托管和部署 - 在 Linux 上使用 Nginx 托管 ASP.NET Core 网站

    翻译自 https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-5.0 本文介 ...

  2. ASP.NET Core 1.0 部署 HTTPS (.NET Framework 4.5.1)

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  3. ASP.NET Core 1.0 部署 HTTPS

    ASP.NET Core 1.0 部署 HTTPS ASP.NET Core 1.0 部署 HTTPS (.NET Framework 4.5.1) 提示 更新时间:2016年01月23日. 在目前介 ...

  4. win10下ASP.NET Core 2.0部署环境搭建(转)

    此文用于记录在win10环境下,新建的Asp.net Core 2.0 Web应用项目如何运行在IIS上 一.运行环境 操作系统: Window10 家庭中文版 版本 10.0.15063 版本 15 ...

  5. .NET Core & ASP.NET Core 1.0在Redhat峰会上正式发布

    众所周知,Red Hat和微软正在努力使.NET Core成为Red Hat企业版Linux (RHEL)系统上的一流开发平台选项.这个团队已经一起工作好几个月了,RHEL对.NET有许多需求.今天在 ...

  6. ASP.NET Core 1.0中实现文件上传的两种方式(提交表单和采用AJAX)

    Bipin Joshi (http://www.binaryintellect.net/articles/f1cee257-378a-42c1-9f2f-075a3aed1d98.aspx) Uplo ...

  7. 用VSCode开发一个基于asp.net core 2.0/sql server linux(docker)/ng5/bs4的项目(2)

    第一部分: http://www.cnblogs.com/cgzl/p/8478993.html 为Domain Model添加约束 前一部分, 我们已经把数据库创建出来了. 那么我们先看看这个数据库 ...

  8. 用VSCode开发一个基于asp.net core 2.0/sql server linux(docker)/ng5/bs4的项目(1)

    最近使用vscode比较多. 学习了一下如何在mac上使用vscode开发asp.netcore项目. 这里是我写的关于vscode的一篇文章: https://www.cnblogs.com/cgz ...

  9. 用VSCode开发一个asp.net core2.0+angular5项目(5): Angular5+asp.net core 2.0 web api文件上传

    第一部分: http://www.cnblogs.com/cgzl/p/8478993.html 第二部分: http://www.cnblogs.com/cgzl/p/8481825.html 第三 ...

随机推荐

  1. MySQL数据库辅助类

    /** *创建人:CalvinR *说明:数据库辅助类 **/ namespace Study.Utilities.MySql_Connect { /// <summary> /// My ...

  2. Mybatis -- 批量更新 -- updateBatch

    mysql数据库配置: 数据库连接必须配置:&allowMultiQueries=true并且‘&’ 用&替换 jdbc.url=jdbc:mysql://192.168.10 ...

  3. [AX2012]在SSRS报表中获取从Menuitem传入的记录

    在较早版本的AX中我们运行一个报表时会用到类RunBaseReport,从它扩展一个子类,再由它运行报表,一个典型的Axapta3中的例子: class ReportProdInfo extends ...

  4. 打破基于OpenResty的WEB安全防护(CVE-2018-9230)

    原文首发于安全客,原文链接:https://www.anquanke.com/post/id/103771 0x00 前言 ​ OpenResty® 是一个基于 Nginx 与 Lua 的高性能 We ...

  5. Ansible Playbook 使用变量

    如何在 Playbook 中定义并使用变量: vars: - user: "test" # 定义变量 tasks: - name: create user user: name=& ...

  6. Elasticsearch 配置同义词

    配置近义词 近义词组件已经是elasticsearch自带的了,所以不需要额外安装插件,但是想要让近义词和IK一起使用,就需要配置自己的分析器了. 首先创建近义词文档 在config目录下 mkdir ...

  7. 用Python编写一个简单的Http Server

    用Python编写一个简单的Http Server Python内置了支持HTTP协议的模块,我们可以用来开发单机版功能较少的Web服务器.Python支持该功能的实现模块是BaseFTTPServe ...

  8. wireshark----linux

    1.[root@lc~]# tshark   Running as user "root" and group "root". This could be da ...

  9. EF的学习

    今天学习了ORM中的Entity FrearmeWork框架,其实之前看到orm框架,感觉好高大上啊,还没准备去了解它那,今天我们就学习了这个,其实Entity FrearmeWork框架和Nhibe ...

  10. codeforces水题100道 第二十六题 Codeforces Beta Round #95 (Div. 2) A. cAPS lOCK (strings)

    题目链接:http://www.codeforces.com/problemset/problem/131/A题意:字符串大小写转换.C++代码: #include <cstdio> #i ...