参考:

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. [LOJ2541]「PKUWC2018」猎人杀

    loj description 有\(n\)个猎人,每个猎人有一个仇恨度\(w_i\),每个猎人死后会开一枪打死一个还活着的猎人,打中每个猎人的概率与他的仇恨度成正比. 现在你开了第一枪,打死每个猎人 ...

  2. 如何重启 Windows 10 子系统(WSL) ubuntu

    如何重启 Windows 10 子系统(WSL) ubuntu WSL 子系统是基于 LxssManager 服务运行的. 只需要将 LxssManager 重启即可. 可以做成一个 bat 文件. ...

  3. 【转】Linux下的文本dos格式转Unix格式,去除^M符号

    原文网址:http://blog.csdn.net/kobejayandy/article/details/13291525 问:我在Windows中通过FTP传一个文本文件到Linux中,但是打开文 ...

  4. 一个filebeat实例 设置多topic设置

    方法1:一实例多topic: https://discuss.elastic.co/t/filebeat-5-0-output-to-kafka-multiple-topics/67934 The d ...

  5. create index 与 alter table add index 区别

    众所周知,MySQL创建索引有两种语法,即:ALTER TABLE HeadOfState ADD INDEX (LastName, FirstName);CREATE INDEX index_nam ...

  6. win7 php5.6 redis扩展

    步骤: 1.下载redis扩展 redis扩展下载地址:http://windows.php.net/downloads/pecl/snaps/redis/ 查看phpinfo下载匹配的版本(一定要选 ...

  7. nginx限制请求之三:Nginx+Lua+Redis 对请求进行限制

    相关文章: <高可用服务设计之二:Rate limiting 限流与降级> <nginx限制请求之一:(ngx_http_limit_conn_module)模块> <n ...

  8. 学习笔记之LeetCode

    LeetCode Online Judge https://leetcode.com/ Leetcode:在线编程网站-各大IT公司的笔试面试题 http://blog.csdn.net/huixin ...

  9. Autofac Property Injection and Method Injection

    While constructor parameter injection is the preferred method of passing values to a component being ...

  10. SpringBoot2.0实现静态资源版本控制

    写在最前面 犹记毕业第一年时,公司每次发布完成后,都会在一个群里通知[版本更新,各部门清理缓存,有问题及时反馈]之类的话.归根结底就是资源缓存的问题,浏览器会将请求到的静态资源,如JS.CSS等文件缓 ...