安装 .NET 8:
参考官方文档安装 SDK 和 Runtime:wget https://dotnet.microsoft.com/download
发布应用:
在开发机执行:dotnet publish -c Release -o ./publish
上传到 Linux 服务器:
使用scp或rsync:scp -r ./publish user@server:/var/www/myapp
运行应用:
cd /var/www/myapp dotnet MyApp.dll
安装 Nginx 并配置反向代理:
安装:
sudo apt install nginx
编辑配置
/etc/nginx/sites-available/default(或新建站点):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:
sudo systemctl restart nginx
后台运行建议:使用 systemd 或
nohup管理进程。
完成后通过浏览器访问服务器 IP 或域名即可。