1. 安装 .net core

可参见官网安装教程。

  1. 选择Linux发行版本为Centos/Oracle
  2. 添加dotnet的yum仓库配置
$ sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
  1. 安装.net SDK
#更新系统软件
sudo yum update
#安装dotnet sdk
sudo yum install dotnet-sdk-2.1
  1. 使用dotnet --info命令显示 .net core 的信息。

2. 安装nginx

可参见官网安装配置教程。

  1. 配置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
  1. 获取公钥文件
wget nginx.org/keys/nginx_signing.key
  1. 导入公钥文件
rpm --import nginx_signing.key
  1. 安装nginx
sudo yum -y install nginx

3. 将nginx设置为开机启动

  1. 在系统服务目录里创建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
  1. 设置为开机启动
systemctl enable nginx.service
  1. 其他管理命令
#启动nginx服务
systemctl start nginx.service  #停止开机自启动
systemctl disable nginx.service #查看服务当前状态
systemctl status nginx.service #重新启动服务
systemctl restart nginx.service  #查看所有已启动的服务
systemctl list-units --type=service

4. 配置nginx

  1. 增加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;
#}
  1. 重新载入ngin
nginx -s reload

5. 发布网站,配置服务和防火墙

  1. 发布网站后将发布后的网站上传到服务器。
  2. 使用dotnet myapp.dll启动网站。
  3. 在浏览器中打开网站的地址,检测网站正常启动并可访问。
  4. 如果需要外网访问需要在防火墙上开放相应的端口。具体操作可参见:
#添加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
  1. 将发布的网站配置为服务,可参见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网站的更多相关文章

  1. CentOS7上部署ASP.Net Core 2.2应用

    前言 在CentOS7上部署ASP.Net Core应用是我的技术路线验证的一部分,下一个产品计划采用ASP.Net Boilerplate Framework开发.因此需要求提前进行一下技术验证,在 ...

  2. ASP.NET Core MVC 网站学习笔记

    ASP.NET Core MVC 网站学习笔记 魏刘宏 2020 年 2 月 17 日 最近因为” 新冠” 疫情在家办公,学习了 ASP.NET Core MVC 网站的一些知识,记录如下. 一.新建 ...

  3. Centos8 Docker+Nginx部署Asp.Net Core Nginx正向代理与反向代理 负载均衡实现无状态更新

    首先了解Nginx 相关介绍(正向代理和反向代理区别) 所谓代理就是一个代表.一个渠道: 此时就涉及到两个角色,一个是被代理角色,一个是目标角色,被代理角色通过这个代理访问目标角色完成一些任务的过程称 ...

  4. asp.net core跨平台--CentOS7.2部署asp.net core网站

    随着vs2015 2017的发布,.NETCore越来越流行了,我就尝试着做了个demo,在centos上试着运行了一下,中间遇到很多问题,不过最后还是成功运行,记录一下过程.废话不多说,直接开始: ...

  5. ASP.Net Core MVC 网站在Windows服务器跑不起来

    1.vs远程发布到服务器,浏览器访问,报错502 2.打开错误提示提供的网址参考 3.安装runtime,sdk,Hosting Bundle Installer,其他操作 .....发现并没有什么用 ...

  6. CentOS7下让Asp.Net Core的网站自动运行

    一.安装Nginx yum install nginx 二.配置Nginx vi /etc/nginx/nginx.conf location / { proxy_pass http://127.0. ...

  7. 阿里云CentOS7部署ASP.NET Core

    本文主要介绍了阿里云CentOS7下如何成功的发布ASP.Core应用并使用nginx进行代理, 并对所踩的坑加以记录; 环境.工具.准备工作 服务器:阿里云64位CentOS 7.4.1708版本; ...

  8. 【翻译】使用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 ...

  9. asp.net core mvc视频A:笔记1.基本概念介绍

    此笔记来自视频教程 MVC本身与三层架构没有联系 使用VS2017新建一个默认的asp.net core mvc网站,认识结构及文件用途.

随机推荐

  1. POJ 2112 Optimal Milking(二分图匹配)

    [题目链接] http://poj.org/problem?id=2112 [题目大意] 给出一些挤奶器,每台只能供给M头牛用,牛和挤奶器之间有一定的距离 现在要让每头牛都挤奶,同时最小化牛到挤奶器的 ...

  2. 冒泡排序--注意flag变量的设置

    代码: #include<stdio.h> void BubbleSort(int a[],int n){ int i,j; int temp; ; // 此处flag变量的设置可以提高算 ...

  3. BlockTransferService 实现

    spark的block管理是通过BlockTransferService定义的方法从远端获取block.将block存储到远程节点.shuffleclient生成过程就会引入blockTransfer ...

  4. Linux 命令缩写部分解释

    转:http://blog.chinaunix.net/uid-28408358-id-3890783.html bin = BINaries  /dev = DEVices  /etc = ETCe ...

  5. 【spring data jpa】jpa实现update操作 字段有值就更新,没值就用原来的

    示例代码如下: /** *复杂JPA操作 使用@Query()自定义sql语句 根据业务id UId去更新整个实体 * 删除和更新操作,需要@Modifying和@Transactional注解的支持 ...

  6. t-SNE和LDA PCA的学习

    t-SNE 可以看这篇文章: http://bindog.github.io/blog/2016/06/04/from-sne-to-tsne-to-largevis/ LDA可以看这篇文章: htt ...

  7. Discuz! 7.1 & 7.2 远程代码执行漏洞

    受影响产品: Discuz! 7.1 & 7.2 漏洞描述: 产生漏洞的$scriptlang数组在安装插件后已经初始化 Discuz!新版本7.1与7.2版本中的showmessage函数中 ...

  8. mongodb权限管理(转)

    Mongodb 预定义角色 Mongodb 中预定义了一些角色,把这些角色赋予给适当的用户上,用户就只能进行角色范围内的操作. 数据库用户角色 (所有数据库都有) read 用户可以读取当前数据库的数 ...

  9. oracle 10g函数大全--转换函数

    chartorowid(c1) [功能]转换varchar2类型为rowid值 [参数]c1,字符串,长度为18的字符串,字符串必须符合rowid格式 [返回]返回rowid值 [示例] SELECT ...

  10. spark完全分布式集群搭建

    最近学习Spark,因此想把相关内容记录下来,方便他人参考,也方便自己回忆吧 spark开发环境的介绍资料很多,大同小异,很多不能一次配置成功,我以自己的实际操作过程为准,详细记录下来. 1.基本运行 ...