Linux系统使用宝塔面板下配置ASP.NET CORE环境 Nginx+mysql

1.登录linux服务器,安装宝塔服务器工具,命令如下(万能安装脚本):

if [ -f /usr/bin/curl ];then curl -sSO https://download.bt.cn/install/install_panel.sh;else wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh;fi;bash install_panel.sh ed8484bec

2.等待安装完成,期间可能要输入Y确认继续执行;安装完成后最后会出现一个网址和帐号密码;输入网址,登录成功后,安装推荐设置NGINX 1.6,mysql5.7,及其他默认
3.等待安装完成后,安装netcore2.2,命令如下:

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc">/etc/yum.repos.d/dotnetdev.repo'

sudo yum update

sudo yum install libunwind libicu

sudo yum install dotnet-sdk-2.2

4.安装完成后,新建ftp及mysql上传到线上,然后找到网站文件路径,执行运行操作:

cd /www/wwwroot/gaoyi
dotnet Ctmon.Web.dll

5.运行完后新建执行持续执行工具,步骤如下:
5.1创建服务

vi /etc/systemd/system/gaoyi.service

5.2写入文件(下面<>部分是需要变更的)

[Unit]
Description=Web API Application running on CentOS

[Service]
WorkingDirectory= /www/wwwroot/gaoyi
ExecStart=/usr/bin/dotnet /www/wwwroot/gaoyi/Ctmon.Web.dll
Restart=always
RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=gaoyi
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

//<>内的内容按所部署位置编写
WorkingDirectory = /www/wwwroot/gaoyi //程序所在目录
ExecStar=/usr/bin/dotnet /www/wwwroot/gaoyi/Ctmon.Web.dll //程序运行DLL
SyslogIdentifier = gaoyi

5.3启动服务

systemctl start website

6.执行完上面后,需要到宝塔修改配置
在这里插入图片描述
配置文件内容(proxy_pass http:端口号不可重复)

server {
listen 80;
server_nane gaoyi.ctmon.cn;
index index.php index.html index.htm default.php default.htm default.html
    location / {
        proxy_pass http://localhost:5005;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

7.保存后,需要重启nginx
在这里插入图片描述

到此网址配置完成
(以上就完成了,但下面会出现一种情况,就是我们修改文件后,需要上传dll到线上,所以需要执行以下步骤)
1.上传对应的dll
2.上传后需要执行以下命令

systemctl stop gaoyi

3.找到对应的网站文件路径,执行运行操作:

cd /www/wwwroot/gaoyi
dotnet Ctmon.Web.dll

4.执行完后需要执行以下命令

systemctl start gaoyi
systemctl enable gaoyi.service #开机运行服务

注释
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop qihang.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

服务器配置常用端口
80:HTTP端口
443:HTTPS端口
21:FTP端口
465:SMTP邮件发送端口
587:个人QQ邮箱发送端口
1433:SQLSERVER数据库端口
3306: MYSQL数据库端口
8888: 宝塔默认端口

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值