centos7+nginx部署asp.net core mvc网站
1. 安装 .net core
可参见官网安装教程。
- 选择Linux发行版本为
Centos/Oracle
- 添加dotnet的yum仓库配置
$ sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
- 安装.net SDK
#更新系统软件
sudo yum update
#安装dotnet sdk
sudo yum install dotnet-sdk-2.1
- 使用
dotnet --info
命令显示 .net core 的信息。
2. 安装nginx
可参见官网安装配置教程。
- 配置yum仓库,创建
/etc/yum.repos.d/nginx.repo
,并配置为以下内容:
[nginx]
name=nginx repo
#baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
#OS为rhel或centos
#OSRELEASE为centos版本,6或7
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
- 获取公钥文件
wget nginx.org/keys/nginx_signing.key
- 导入公钥文件
rpm --import nginx_signing.key
- 安装nginx
sudo yum -y install nginx
3. 将nginx设置为开机启动
- 在系统服务目录里创建nginx.service文件,并将文件内容设置如下:
touch /etc/systemd/system/nginx.service
#服务的说明
[Unit]
#描述服务
Description=nginx
#描述服务类别
After=network.target
#服务运行参数的设置
[Service]
#Type=forking是后台运行的形式
Type=forking
#服务的具体运行命令
ExecStart=/usr/sbin/nginx
#重启命令
ExecReload=/usr/sbin/nginx -s reload
#停止命令
ExecStop=/usr/sbin/nginx -s quit
#PrivateTmp=True表示给服务分配独立的临时空间
PrivateTmp=true
#运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
[Install]
WantedBy=multi-user.target
- 设置为开机启动
systemctl enable nginx.service
- 其他管理命令
#启动nginx服务
systemctl start nginx.service
#停止开机自启动
systemctl disable nginx.service
#查看服务当前状态
systemctl status nginx.service
#重新启动服务
systemctl restart nginx.service
#查看所有已启动的服务
systemctl list-units --type=service
4. 配置nginx
- 增加Nginx配置文件myapp.conf,并做如下配置:
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/myapp.conf
proxy_set_header Host $http_host
server {
#监听端口号
listen 8081;
#监听地址
server_name localhost 192.168.1.202;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
#设置代理
location / {
#Kestrel上运行的asp.net core mvc网站地址
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
- 重新载入ngin
nginx -s reload
5. 发布网站,配置服务和防火墙
- 发布网站后将发布后的网站上传到服务器。
- 使用
dotnet myapp.dll
启动网站。 - 在浏览器中打开网站的地址,检测网站正常启动并可访问。
- 如果需要外网访问需要在防火墙上开放相应的端口。具体操作可参见:
#添加80端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
#删除防火墙端口:
firewall-cmd --zone=public --remove-port=12345/tcp --permanent
#重新加载防火墙:
firewall-cmd --reload
#重启防火墙:
systemctl stop firewalld systemctl start firewalld
- 将发布的网站配置为服务,可参见nginx配置为开机启动。具体如下:
#新建配置文件
touch /etc/systemd/system/myapp.service
#编辑配置文件:
[Unit]
Description=myapp web
[Service]
WorkingDirectory=/home/myapp/web
ExecStart=/usr/bin/dotnet /home/myapp/web/WebPortals.dll
Restart=always
RestartSec=10 # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=myapp
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
#服务开机启动
systemctl enable myapp.service
#启动服务
systemctl start myapp.service
#查看服务状态
systemctl status myapp.service
centos7+nginx部署asp.net core mvc网站的更多相关文章
- CentOS7上部署ASP.Net Core 2.2应用
前言 在CentOS7上部署ASP.Net Core应用是我的技术路线验证的一部分,下一个产品计划采用ASP.Net Boilerplate Framework开发.因此需要求提前进行一下技术验证,在 ...
- ASP.NET Core MVC 网站学习笔记
ASP.NET Core MVC 网站学习笔记 魏刘宏 2020 年 2 月 17 日 最近因为” 新冠” 疫情在家办公,学习了 ASP.NET Core MVC 网站的一些知识,记录如下. 一.新建 ...
- Centos8 Docker+Nginx部署Asp.Net Core Nginx正向代理与反向代理 负载均衡实现无状态更新
首先了解Nginx 相关介绍(正向代理和反向代理区别) 所谓代理就是一个代表.一个渠道: 此时就涉及到两个角色,一个是被代理角色,一个是目标角色,被代理角色通过这个代理访问目标角色完成一些任务的过程称 ...
- asp.net core跨平台--CentOS7.2部署asp.net core网站
随着vs2015 2017的发布,.NETCore越来越流行了,我就尝试着做了个demo,在centos上试着运行了一下,中间遇到很多问题,不过最后还是成功运行,记录一下过程.废话不多说,直接开始: ...
- ASP.Net Core MVC 网站在Windows服务器跑不起来
1.vs远程发布到服务器,浏览器访问,报错502 2.打开错误提示提供的网址参考 3.安装runtime,sdk,Hosting Bundle Installer,其他操作 .....发现并没有什么用 ...
- CentOS7下让Asp.Net Core的网站自动运行
一.安装Nginx yum install nginx 二.配置Nginx vi /etc/nginx/nginx.conf location / { proxy_pass http://127.0. ...
- 阿里云CentOS7部署ASP.NET Core
本文主要介绍了阿里云CentOS7下如何成功的发布ASP.Core应用并使用nginx进行代理, 并对所踩的坑加以记录; 环境.工具.准备工作 服务器:阿里云64位CentOS 7.4.1708版本; ...
- 【翻译】使用Visual Studio创建Asp.Net Core MVC (一)
This tutorial will teach you the basics of building an ASP.NET Core MVC web app using Visual Studio ...
- asp.net core mvc视频A:笔记1.基本概念介绍
此笔记来自视频教程 MVC本身与三层架构没有联系 使用VS2017新建一个默认的asp.net core mvc网站,认识结构及文件用途.
随机推荐
- [Contest20180426]校门外的树
$\newcommand{\align}[1]{\begin{align*}#1\end{align*}}$题意:对于一个排列$p_{1\cdots n}$构造一个图,如果$i\lt j$且$p_i\ ...
- 【可持久化Trie】模板
总算找到个能看懂的了,orz Lavender. #define INF 2147483647 #define N 100001 #define MAXBIT 31 int root[N],ch[N* ...
- 【枚举】【二分答案】【分块答案】【BFS】【最大流】【Dinic】bzoj1189 [HNOI2007]紧急疏散evacuate
[法一]枚举Time(0~N*M): S->'.'(1); 'D'->T(Time); '.'->'D'(dis(用BFS预处理,注意一旦到达'D',BFS就不能继续扩展了,注意di ...
- Intellij IDEA光标保持自动缩进,设置下次不放在行首
- winfrom向窗体中拖放图片并显示
首先要设置窗体的AllowDrop属性为true.然后在窗体的DragEnter事件中添加如下代码:调用自定义的显示图片的方法. #region "在用鼠标将某项拖放到区域时事件" ...
- SQL CTE 递归分割以逗号分隔的字符串
)) INSERT INTO @t SELECT 'AAA,BBB,CCC' SELECT * FROM @t ;WITH mycte AS ( ,mend,num FROM @t UNION ALL ...
- java 的 CopyOnWriteArrayList类
初识CopyOnWriteArrayList 第一次见到CopyOnWriteArrayList,是在研究JDBC的时候,每一个数据库的Driver都是维护在一个CopyOnWriteArrayLis ...
- 各种Lisp系语言大检阅
主要特色: CommonLISP : lisp系集大成者, 工业化强度的大型语言. 拥有理论上最高的表达力, 非常复杂, 学习难度极大. 喜欢的人捧到天上, 觉得它是一切语言的终点, 不喜欢的人恶心死 ...
- iOS:APNS推送主要代码
首先,在AppDelegate.m 中: 1,注册通知 //[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片 - (BOOL)application:(UI ...
- Heartbleed漏洞利用程序
#!/usr/bin/python # Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (jspenguin@jspe ...