centos 安装部署.net core站点
参考:
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站点的更多相关文章
- 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 ...
- ASP.NET Core学习之四 在CentOS上部署.net core
一.安装CentOs 以前在大学学过linux,但是对命令行总是有一种深深的排斥感,几年之后,还是又回来了. 1.下载 现在没法FQ,就算是FQ网速也是蜗牛一样慢,我使用阿里云的镜像站进行下载速度还是 ...
- centos 安装部署zabbix
Zabbix_server初始安装部署 各模块要安装的模块 Server:server+nginx+mysql+php Agentd:agentd Proxy:proxy+mysql 1.准备环境: ...
- CentOS上部署.net core
1.阿里云更换系统安装CentOS7.4 64位版本 2.试用XShell 5 登录服务器 参考https://www.microsoft.com/net/learn/get-started/linu ...
- CentOS 安装Asp.net Core & FTP服务
网络设置 确认是否成功连网: ping baidu.com 如果无法上网请检查以下设置 ip link show vim /etc/sysconfig/network-scripts/ipcfg-(看 ...
- nginx部署dotnet core站点
步骤 aspnetcore程序端口号5001,实际外部端口号8001,相当于把8001收到的请求转发给5001. 把发布出来的文件全部丢掉 /var/www/JuXiangTou 里面去.可以用scp ...
- CentOS+Linux部署.NET Core应用程序
工具: WinSCP+Xshell+VMware 1.安装CentOS 省略安装过程... 2. 安装.Net Core Sdk ①更新可用的安装包:sudo yum update ②安装.NET需要 ...
- CentOS安装部署jumperserver(堡垒机)
可以参考官方的文档:http://docs.jumpserver.org/zh/docs/introduce.html 测试环境 系统: CentOS 7 IP: 192.168.244.144 设置 ...
- CENTOS安装部署zabbix
果学网 -专注IT在线www.prismcollege.com 參考原文:http://www.showerlee.com/archives/13 RHCE过的EMAIL已经下来.所以近期闲了就准备把 ...
随机推荐
- Hibernate环境搭建+struts整合
说明:本文档,是和struts2+hibernate的整合示例. lib下还有struts2的jar包,本示例没有显示.struts2的搭建参考struts2的环境搭建 一下载hibernate的ja ...
- IIS7Appcmd 命令详解
IIS7 Appcmd 命令详解 废话不说!虽然有配置界面管理器!但是做安装包的时候命令创建是必不可少的!最近使用NSIS制作安装包仔细研究了一下Appcmd的命令,可谓是功能齐全. 上网查了些资料, ...
- 列表查询SQL语句改造
一个经常遇到到的场景,就是查询列表数据,列表数据由多张表构成 最简单的查询方法是先写一个查询单条数据的方法,比如这个方法中要查询十张表: 然后一个循环调用查单条的方法,这种逻辑上理解是比较简单的(因为 ...
- Guid.NewGuid().ToString()生成唯一码js
Guid.NewGuid().ToString() 生成唯一码,用户生成随机id 生成唯一编码,版本控制对比等. //表示全局唯一标识符 (GUID). function Guid(g) { var ...
- WebDriverException: Message: 'phantomjs.exe' executable needs to be in PATH.
本文转载自:http://blog.csdn.net/sinat_36764186/article/details/55520444 网上的某测试代码: from selenium import we ...
- Java 字符串 String
什么是Java中的字符串 在 Java 中,字符串被作为 String 类型的对象处理. String 类位于 java.lang 包中.默认情况下,该包被自动导入所有的程序. 创建 String 对 ...
- php错误:Uncaught exception com_exception with message Failed to create COM object
本文为大家讲解的是php错误:Uncaught exception com_exception with message Failed to create COM object,感兴趣的同学参考下. ...
- thinkPHP volist标签循环输出多维数组
<volist name="company" id="vo">{$vo.company_name}<volist name="vo[ ...
- java 查询solr时间格式
solr时间格式是2015-07-06T00:00:00.0Z,所以下面是把当前时间做转换 SimpleDateFormat format = new SimpleDateFormat("y ...
- [转]MongoDB随笔2:使用查询
转自:http://www.cnblogs.com/yangecnu/archive/2011/07/16/2108450.html 一.通过查询获取数据 在深入讨论查询之前,首先来了解一下查询返回的 ...