参考:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx

https://docs.microsoft.com/en-us/dotnet/core/linux-prerequisites

https://docs.microsoft.com/zh-cn/dotnet/core/install/linux-package-manager-centos7

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer

发布程序

dotnet publish --configuration Release

服务器安装 net core runtime

sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
sudo yum update -y #使用2.1
sudo yum install aspnetcore-runtime-2.1
#使用3.1
sudo yum install aspnetcore-runtime-3.1
#查看版本
dotnet --info

服务守护

创建文件/etc/systemd/system/kestrel-helloapp.service

[Unit]
Description=Example .NET Web API App running on Ubuntu [Service]
WorkingDirectory=/var/www/helloapp
ExecStart=/usr/bin/dotnet /var/www/helloapp/helloapp.dll #服务运行的命令行
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=https://+:443;http://+:80;http://+:5000 #通过环境遍历设置端口
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install]
WantedBy=multi-user.target

可选:上面kestrel-helloapp.service通过ASPNETCORE_URLS环境变量设置了开放的端口,也可通过UseUrls代码强行指定

2.x:
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*:5000;") //通过UseUrls使用特定端口
.UseStartup<Startup>()
.Build();
} 3.x:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseUrls("http://*:5000;");
});

服务启动

systemctl enable kestrel-helloapp.service
systemctl start kestrel-helloapp.service
systemctl status kestrel-helloapp.service

配置防火墙端口

firewall-cmd --permanent --zone=public --add-port=5000/tcp
firewall-cmd --reload

nginx转发

修改程序,支持代理转发

using Microsoft.AspNetCore.HttpOverrides;

services.Configure<ForwardedHeadersOptions>(options =>
{
//options.KnownProxies.Add(IPAddress.Parse("192.168.56.10"));
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
}); app.UseForwardedHeaders();

添加nginx配置

/etc/nginx/conf.d/xx.conf

server {
listen 80;
server_name example.com *.example.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 $http_host; #此处官方文档使用的$host缺少端口号
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

centos 安装部署.net core站点的更多相关文章

  1. Ubuntu 18.04 安装部署Net Core、Nginx全过程

    Ubuntu 18.04 安装部署Net Core.Nginx全过程 环境配置 Ubuntu 18.04 ,Nginx,.Net Core 2.1, Let's Encrypt 更新系统 sudo a ...

  2. ASP.NET Core学习之四 在CentOS上部署.net core

    一.安装CentOs 以前在大学学过linux,但是对命令行总是有一种深深的排斥感,几年之后,还是又回来了. 1.下载 现在没法FQ,就算是FQ网速也是蜗牛一样慢,我使用阿里云的镜像站进行下载速度还是 ...

  3. centos 安装部署zabbix

    Zabbix_server初始安装部署 各模块要安装的模块 Server:server+nginx+mysql+php Agentd:agentd Proxy:proxy+mysql 1.准备环境: ...

  4. CentOS上部署.net core

    1.阿里云更换系统安装CentOS7.4 64位版本 2.试用XShell 5 登录服务器 参考https://www.microsoft.com/net/learn/get-started/linu ...

  5. CentOS 安装Asp.net Core & FTP服务

    网络设置 确认是否成功连网: ping baidu.com 如果无法上网请检查以下设置 ip link show vim /etc/sysconfig/network-scripts/ipcfg-(看 ...

  6. nginx部署dotnet core站点

    步骤 aspnetcore程序端口号5001,实际外部端口号8001,相当于把8001收到的请求转发给5001. 把发布出来的文件全部丢掉 /var/www/JuXiangTou 里面去.可以用scp ...

  7. CentOS+Linux部署.NET Core应用程序

    工具: WinSCP+Xshell+VMware 1.安装CentOS 省略安装过程... 2. 安装.Net Core Sdk ①更新可用的安装包:sudo yum update ②安装.NET需要 ...

  8. CentOS安装部署jumperserver(堡垒机)

    可以参考官方的文档:http://docs.jumpserver.org/zh/docs/introduce.html 测试环境 系统: CentOS 7 IP: 192.168.244.144 设置 ...

  9. CENTOS安装部署zabbix

    果学网 -专注IT在线www.prismcollege.com 參考原文:http://www.showerlee.com/archives/13 RHCE过的EMAIL已经下来.所以近期闲了就准备把 ...

随机推荐

  1. Plus and Square Root

    ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ...

  2. 《DSP using MATLAB》Problem 2.7

    1.代码: function [xe,xo,m] = evenodd_cv(x,n) % % Complex signal decomposition into even and odd parts ...

  3. office 2013 图标编辑

    1,找图标,网站:https://www.iconfinder.com/ 2,找到图标后用qq截图,之后粘贴到Adobe Illustrator 里边. 3,选定图像后,点击对象->图像描摹-& ...

  4. 【转】open-falcon监控windows机器

    open-falcon监控windows机器 时间:2016-05-22 15:34:04   来源:眷恋江南   编辑:涛涛   点击:791   A-A+     最近公司上线了一款新的游戏,用的 ...

  5. Non-standard evaluation, how tidy eval builds on base R

    As with many aspects of the tidyverse, its non-standard evaluation (NSE) implementation is not somet ...

  6. 黄聪:360浏览器、chrome开发扩展插件教程(3)关于本地存储数据

    转载:http://www.cnblogs.com/walkingp/archive/2011/04/04/2003875.html HTML5中的localStorage localStorage与 ...

  7. sdk下载地址

    http://www.androiddevtools.cn/ 容器,然后跟着下面的提示下载对应需要的包 放到对应的位置 即可

  8. 面试总结之MISC(操作系统,网络,数学,软件开发,测试,工具,系统设计,算法)

    操作系统 解释堆和栈的区别. 分配在堆的内存与分配在堆栈的内存有什么不同 分配在堆的内存要手动去释放 线程与进程的区别 多线程中栈与堆是公有的还是私有的 在多线程环境下,每个线程拥有一个栈和一个程序计 ...

  9. 一些部署django用到的linux命令

    mv untitled45/ /1601F/wang/ 将XXXX移动到XXX,也可以用于给XXX重新命名 zip -r -q -o hello.zip  /1601F/3/untitled45 安静 ...

  10. java之mail发送

    一.邮箱的应用在实际的Java开发过程中,也是非常常见的.我这里就是写了一个简单的邮箱发送功能. 二.邮箱的基本配置,使用的是JavaMailSender的提供的方式来实现邮件的发送 1)qq邮箱的配 ...