在安装.NET Core前,须要注册Microsoft签名秘钥并添加Microsoft产品提要,每台机器只须要注册一次,执行以下命令:html
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum install aspnetcore-runtime-3.1 # 验证dotnet core runtime是否安装成功 dotnet #查看系统中包含的.net core runtime版本 dotnet --list-runtimes
在CentOS系统中,建立/home/publish/demo文件夹nginx
mkdir /home/publish /home/publish/demo
在Visual Studio 2019中建立Web应用Linux.Web,发布为文件夹,并经过FXTP上传到publish/demo文件夹下vim
# 安装nginx yum install nginx # 启动nginx systemctl start nginx # 设为开机启动 systemctl enable nginx
能够经过浏览器访问服务器地址 http://ip:80 来看看nginx运行状况浏览器
使用XFTP修改 /etc/nginx/conf.d/default.conf 文件,添加以下配置bash
server { listen 8000; 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; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
nginx -s reload
cd /home/publish/demo dotnet Linux.Web.dll
经过浏览器访问 http://ip:8000 此时已经能够访问在CentOS上部署的站点了!服务器
vim /etc/systemd/system/demoapp.service
[Unit] Description=Demo .NET Web Application running on CentOS 7 [Service] WorkingDirectory=/home/publish/demo ExecStart=/usr/bin/dotnet /home/publish/demo/Linux.Web.dll Restart=always RestartSec=20 SyslogIdentifier=dotnet-demo User=nginx Environment=ASPNETCORE_ENVIRONMENT=Production [Install] WantedBy=multi-user.target
systemctl enable demoapp.service
systemctl start demoapp.service systemctl status demoapp.service
原文出处:https://www.cnblogs.com/weiwxg/p/11995577.htmlapp