参考:

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. HDU1735 字数统计

    版权声明:长风原创 https://blog.csdn.net/u012846486/article/details/28011667 字数统计 Time Limit: 1000/2000 MS (J ...

  2. MySQL 数据类型(float)的注意事项

    摘要:      今天左哥问起一个float浮点数类型的问题,这个类型用的不多,所以也不太了解,现在打算测试下. 知识点:      float:浮点数,单精度,占4字节. 测试 root@local ...

  3. 不以main为入口的函数

    先看一段程序 #include <stdio.h> void test() { printf("Hello Word!\n"); return 0; } 没有main函 ...

  4. SpringCloud初体验:一、Eureka 服务的注册与发现

    Eureka :云端服务发现,一个基于 REST 的服务,用于定位服务,以实现云端中间层服务发现和故障转移. Eureka 可以大致理解为 房产中介 和 房东 的关系,房东想让租客租房子,首先要把房子 ...

  5. 查看ms SQL Server存储过程,函数的内容

    方法1:最简单的,右键单击要查看的存储过程,选择“修改”: 方法2: SELECT definition FROM solar.sys.sql_modules WHERE [object_id]=(O ...

  6. erlang程序发布的时候需要注意的地方

    假如你的程序依赖三方application,比如cowboy,启动三方程序有两种方式 在erl脚本里面手工启动,这种在使用rebar generate打包的时候和发布beam的时候都可以用 appli ...

  7. URL 收录

    http://www.cnblogs.com/Olive116/p/3426957.html 地图控件 http://www.cnblogs.com/tugenhua0707/ 前端

  8. sqlite性能优化

    1.数据库性能上 1.1 批量事务插入,提升数据插入的性能 由于sqlite默认每次插入都是事务,需要对文件进行读写,那么减少事务次数就能简书磁盘读写次数从而获得性能提升. 1.2 单条sql优于多条 ...

  9. javascript中不存在块级作用域,所以要小心使用在块级作用域中的函数声明所带来的作用域混乱.

    在javascript中函数的作用域是一个非常重要的概念. javascript中是没有块级作用域,但是有函数作用域的概念. 我们在开发的过程中,经常会遇到这样的问题, 某个函数我暂时不需要,不想声明 ...

  10. 为什么重写equals后要重写hashCode

    equals和hashCode的关系 要搞清楚题目中的问题就必须搞明白equals方法和hashCode方法分别是什么,和诞生的原因,当搞明白了这一点其实题目就不算是个问题了,下面我们来探讨分别探讨一 ...