centeros 部署 .netcore

本文介绍如何在CentOS上部署ASP.NET Core应用程序,包括安装.NET Core运行时与SDK、配置Nginx作为反向代理、设置防火墙规则、上传程序文件及验证程序运行状态等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、安装运行时:
地址:https://www.microsoft.com/net/download/linux-package-manager/centos/runtime-2.1.1
2、安装sdk:
地址:https://www.microsoft.com/net/download/linux-package-manager/centos/sdk-2.1.301
3、安装nginx:

curl -o  nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx.rpm
yum install nginx
systemctl start nginx 启动nginx。
systemctl enable nginx 设置nginx的开机启动

4、配置防火墙:

firewall-cmd --zone=public --add-port=80/tcp --permanent(开放80端口)
systemctl restart firewalld(重启防火墙以使配置即时生效)

5、使用ftp软件上传程序:secureCrt上传很麻烦,经常出现was skipped错误,网站程序通常在var目录下,如:/var/aspnetcore/testmvc
6、检查程序是否能正常运行:

dotnet /var/aspnetcore/testmvc/testmvc.dll

查看是否正常访问:

curl http://localhost:5000

7、修改nginx配置文件:地址是 /etc/nginx/conf.d/default.conf,内容为:

server {
    listen       80;
    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 $host;
        proxy_cache_bypass $http_upgrade;
    }

}

执行命令使配置生效

nginx –s reload

其他参考:
https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.1&tabs=aspnetcore2x

https://www.cnblogs.com/ants/p/5732337.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值