donet core 应用 部署到CentOS
创建应用
新建一个Asp.net core Web API 应用

在program里指定监听端口
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Listen(IPAddress.Any, );
})
.Build();
在应用目录使用dotnet publish 发布文件

将发布的文件上传至CentOS里面
使用命令测试
dotnet WebApplication1.dll

打开浏览器:http://10.15.4.155:5000/api/values

配置反向代理
修改Nginx配置
vi /usr/local/nginx/conf/nginx.conf
添加反向代理
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 $http_host;
proxy_cache_bypass $http_upgrade;
}
}
重新启动Nginx
service nginx reload
打开浏览器:http://10.15.4.155:8001/api/values

在CentOS中,要想在不退出Web服务的情况下返回shell,可以按Ctrl+Z,此时如果想要关掉Web应用,可以先查找进程,然后杀掉
ps -ef | grep WebApplication1
netstat -anp|grep

kill -

配置SSL
使用OpenSSL生成证书
首先自己创建根证书 root 自己做CA也就是发行者。
openssl genrsa -des3 -out root.key
然后按照提示输入密码
openssl req -new -key root.key -out root.csr
输入刚才设置的密码,然后填写一些信息
然后创建一个10年期根证书 root.crt
openssl x509 -req -days -sha1 -extensions v3_ca -signkey root.key -in root.csr -out root.crt
接下来创建服务器证书
openssl genrsa -des3 - openssl req -new -key server.key -out server.req openssl x509 -req -days -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAserial root.srl -CAcreateserial -in server.key -out server.crt
导出pfx格式
openssl pkcs12 -export -in server.crt -inkey server.key -out server.pfx
将生成的server.pfx通过放到网站根目录下
修改Startup的ConfigureServices要求全局使用HTTPS
//配置使用HTTPS
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
修改Configure
//HTTP重定向到HTTPS
var options = new RewriteOptions().AddRedirectToHttps();
app.UseRewriter(options);
修改program代码
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Listen(IPAddress.Any, ,listenOptions=> {
listenOptions.UseHttps("server.pfx","test");
});
})
.Build();
重新发布到CentOS中,记得将证书也放到目录中
开启应用

打开浏览器

使用HTTP是无法打开的。
使用程序访问
static void Main(string[] args)
{
string url = "https://localhost/api/values";
using (HttpClient client = new HttpClient())
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
var response = client.GetAsync(url);
Console.WriteLine(response.Result.Content.ReadAsStringAsync().Result);
}
Console.ReadKey();
}

当实际生产部署的时候就不用自签名证书了,一般SSL证书供应商都会提供几种格式的证书

这里选用IIS的就可以,一般在申请证书的时候如果使用了密码,那么生成的IIS证书里面就不带密码,如果申请的时候不使用密码,那么生成的IIS证书目录下会有个随机密码

将网站应用部署成服务
创建配置文件
vi /etc/systemd/system/hellomvc.service
编辑文件
[Unit] Description=Example .NET Web API App running on CentOS [Service] WorkingDirectory=/opt/WebWithSSL/ ExecStart=/usr/bin/dotnet /opt/WebWithSSL/WebApplication1.dll Restart=always RestartSec= # Restart service after seconds if dotnet service crashes SyslogIdentifier=dotnet-example User=root Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi-user.target
启用服务
systemctl enable hellomvc.service
启动服务
systemctl start hellomvc.service
查看服务状态
systemctl status hellomvc.service

这里的 /usr/bin/dotnet 是dotnet默认安装位置,后面的是网站应用的文件位置。
donet core 应用 部署到CentOS的更多相关文章
- dotNet core 应用部署至 centos(超详解附截图)
文章来源:公众号-智能化IT系统. 需要安装的插件以及支撑架构 1.dotnetSDK dotnet 相关命令是属于 .NET Core command-line (CLI) 的一部分,Microso ...
- 1.6部署到CentOS「深入浅出ASP.NET Core系列」
希望给你3-5分钟的碎片化学习,可能是坐地铁.等公交,积少成多,水滴石穿,谢谢关注. 安装.NET Core 官方安装地址: https://www.microsoft.com/net/learn/d ...
- Asp.Net Core 程序部署到Linux(centos)生产环境(二):docker部署
运行环境 照例,先亮环境:软件的话我这里假设你已经批准好了.net core 运行环境,未配置可以看我的这篇[linux(centos)搭建.net core 运行环境] 腾讯云 centos:7.2 ...
- Asp.Net Core 程序部署到Linux(centos)生产环境(一):普通部署
运行环境 照例,先亮底 centos:7.2 cpu:1核 2G内存 1M带宽 辅助工具:xshell xftp 搭建.net core运行环境 .net core 的运行环境我单独写了一篇,请看我的 ...
- 【ASP.NET Core快速入门】(四)在CentOS上安装.NET Core运行时、部署到CentOS
下载.NET Core SDK 下载地址:https://www.microsoft.com/net/download/windows 第一步:Add the dotnet product feed( ...
- .Net Core 使用 System.Drawing.Common 部署到CentOS上遇到的问题
一开始报这个错误:Unable to load shared library 'libdl' 找到libdl安装位置是/usr/lib64: #locate libdl /usr/lib64/libd ...
- 菜鸟入门【ASP.NET Core】4:在CentOS上安装.NET Core运行时、部署到CentOS
下载.NET Core SDK 下载地址:https://www.microsoft.com/net/download/windows 第一步:Add the dotnet product feed( ...
- .NET Core 部署到CentOS–1.创建项目,简单部署
开发环境:Windows 10,部署环境:阿里云 CentOS 7.3 1. 创建应用 1) 创建项目, 配置应用生成部署包 2) 配置项目 编辑project.json, 追加环境项, 选项可参考这 ...
- .NET Core 部署到CentOS–2.创建守护进程, 通过Nginx公网访问
继上一篇, 我们确定在内网可以通过 "http://localhost:5000",可以访问到站点后,接下来我们要配置"守护进程","Nginx公网8 ...
随机推荐
- adb push init.rc /
http://blog.csdn.net/jumper511/article/details/28856249 修改Android init.rc文件后,需要将修改后的文件上传到手机,但是发下如下问题 ...
- ubuntu-server-12.04.2安装配置jdk
原文链接:http://blog.csdn.net/amymengfan/article/details/9958461 我选择的是离线安装,这需要先下载好jdk安装包(下载地址:http://www ...
- ArcGIS的地理坐标系与大地坐标系
一直以来,总有很多朋友针对地理坐标系.大地坐标系这两个概念吃不透.近日,在网上看到一篇文章介绍它们,非常喜欢.所以在此转发一下,希望能够对制图的朋友们有所帮助. 地理坐标:为球面坐标. 参考平面地是 ...
- Failed to place enough replicas
如果DataNode的dfs.datanode.data.dir全配置成SSD类型,则执行"hdfs dfs -put /etc/hosts hdfs:///tmp/"时会报如下错 ...
- sys/time.h 和 time.h
今天在燕麦工作第二天.看荣哥给我的程序,发现程序里面用的延时跟我以前使用的不同.导入两个头文件,然后用函数来获得时间.关于这个函数特别查来一下. time.h 是ISO C99 标准日期头文件. s ...
- 移动端 - APP测试要点
功能测试 1.运行 1)App安装完成后的试运行,可正常打开软件. 2)App打开测试,是否有加载状态进度提示. 3)App页面间的切换是否流畅,逻辑是否正确. 2.注册 1)同表单编辑页面 2)用户 ...
- Phalanx (hdu 2859)
http://acm.hdu.edu.cn/showproblem.php?pid=2859 Time Limit: 10000/5000 MS (Java/Others) Memory ...
- hdu 5073 有坑+方差贪心
http://acm.hdu.edu.cn/showproblem.php?pid=5073 就是给你 n 个数,代表n个星球的位置,每一个星球的重量都为 1 开始的时候每一个星球都绕着质心转动,那么 ...
- Crontab有关
AIX下面 0,2,4,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,58 * * * * /usr/s ...
- [leetcode 120]triangle 空间O(n)算法
1 题目 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjac ...