ASP.NET Core Web在CentOS中结合Nginx托管的部署

1、安装Nginx,此处省略

2、安装ASP.NET Core,参考微软官方的安装教程:

在 Linux 发行版上安装 .NET - .NET | Microsoft Learn

3、使用你电脑的VS创建一个ASP.NET Core Web 项目,注意.NET版本必须和你在centos上安装的版本一样,然后把发布的程序文件上传到你centos指定目录

4、进入centos的 /etc/systemd/system目录,新建一个文件,文件名为 mydotnet.service

后缀名必须是.service,文件名自取

内容如下:

复制代码
[Unit]
Description=DotnetCore-7 Program

# Service 配置参数
[Service]
Type=simple
GuessMainPID=true

//发布后的项目程序目录
WorkingDirectory=/home/wwwroot/myweb
StandardOutput=journal
StandardError=journal

//这条语句执行项目程序目录中的主程序 dll
ExecStart=/usr/bin/dotnet idcweb.dll 
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

5、启用mydotnet.service,执行命令:systemctl enable mydotnet.service

6、重启服务后,每次开机都会启动程序,如果更新程序需要重启可以使用systemctl手动重启

7、在nginx的配置文件中,网站配置的server段改为(参考)

复制代码
server
    {
        listen 80;
        #listen [::]:80;
        server_name 你的域名 ;
        location / {
        
                           #5000是.net程序的端口号,你也可以用 netstat 命令先看下
        proxy_pass         http://127.0.0.1:5000/;

        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection $connection_upgrade;
        proxy_set_header   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;
    }

8、之后,每次更新网站,不需要重启nginx,之需要重启.net程序

相关推荐
恋恋风尘hhh44 分钟前
滑动验证码前端安全研究:以顶象(dingxiang-inc)为例
前端·安全
君穆南7 小时前
基于 NFS 与 Rsync 实现跨服务器 Seafile 数据平滑迁移实战
linux·运维·git
bloglin999997 小时前
scp、rsync远程文件同步
linux·运维·服务器
迦南的迦 亚索的索7 小时前
LINUX环境
linux·运维·服务器
yuanjj887 小时前
linux下调试域格CLM920 NC5等9x07平台模块 QMI拨号
linux·运维·服务器
懂懂tty8 小时前
React状态更新流程
前端·react.js
IMPYLH8 小时前
Linux 的 printenv 命令
linux·运维·服务器·bash
SilentSamsara8 小时前
SSH 远程管理:密钥登录 + 隧道转发,一次性配置好
linux·运维·服务器·ubuntu·centos·ssh
LN花开富贵8 小时前
【ROS】鱼香ROS2学习笔记一
linux·笔记·python·学习·嵌入式·ros·agv
小码哥_常8 小时前
告别繁琐!手把手教你封装超实用Android原生Adapter基类
前端