在安裝.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