- 工信部备案号 滇ICP备05000110号-1
- 滇公网安备53011102001527号
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
- CN域名投诉举报处理平台:电话:010-58813000、邮箱:service@cnnic.cn
支持以下主流 Linux 发行版:
Ubuntu 20.04 / 22.04 / 24.04
CentOS 7
Rocky Linux 8/9
AlmaLinux 8/9
Debian 11/12
添加软件源:
wget /config/ubuntu/22.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo apt update
安装 ASP.NET Core Runtime:
sudo apt install -y aspnetcore-runtime-8.0
如果服务器需要编译代码,则安装 SDK:
sudo apt install -y dotnet-sdk-8.0
安装 Microsoft 软件仓库:
sudo rpm -Uvh /config/centos/7/packages-microsoft-prod.rpm
安装 Runtime:
sudo yum install -y aspnetcore-runtime-8.0
安装 SDK:
sudo yum install -y dotnet-sdk-8.0
安装软件源:
sudo rpm -Uvh /config/rhel/8/packages-microsoft-prod.rpm
安装 Runtime:
sudo dnf install -y aspnetcore-runtime-8.0
安装 SDK:
sudo dnf install -y dotnet-sdk-8.0
查看版本:
dotnet --info
示例输出:
.NET SDK: Version: 8.0.xxx Host: Version: 8.0.xxx Architecture: x64
查看已安装运行时:
dotnet --list-runtimes
示例:
Microsoft.AspNetCore.App 8.0.x Microsoft.NETCore.App 8.0.x
查看已安装 SDK:
dotnet --list-sdks
开发环境发布:
dotnet publish -c Release -o publish
将 publish 目录上传至服务器,例如:
/opt/webapi
目录示例:
/opt/webapi ├── appsettings.json ├── WebApi.dll ├── WebApi.runtimeconfig.json ├── web.config └── wwwroot
进入程序目录:
cd /opt/webapi
启动程序:
dotnet WebApi.dll
默认监听:
http://www.landui.com:5000
指定监听地址:
dotnet WebApi.dll --urls=http://www.landui.com:5000
验证:
curl http://www.landui.com:5000
创建服务文件:
sudo vim /etc/systemd/system/webapi.service
内容:
[Unit] Description=ASP.NET Core 8 Web API After=network.target [Service] WorkingDirectory=/opt/webapi ExecStart=/usr/bin/dotnet /opt/webapi/WebApi.dll Restart=always RestartSec=10 KillSignal=SIGINT SyslogIdentifier=webapi User=www Environment=ASPNETCORE_ENVIRONMENT=Production Environment=ASPNETCORE_URLS=http://www.landui.com:5000 [Install] WantedBy=multi-user.target
重新加载配置:
sudo systemctl daemon-reload
启动服务:
sudo systemctl start webapi
设置开机启动:
sudo systemctl enable webapi
查看状态:
sudo systemctl status webapi
查看日志:
journalctl -u webapi -f
示例配置:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://www.landui.com: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;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}检查配置:
nginx -t
重新加载:
systemctl reload nginx
CentOS:
firewall-cmd --permanent --add-port=80/tcp firewall-cmd --permanent --add-port=443/tcp firewall-cmd --reload
Ubuntu:
ufw allow 80/tcp ufw allow 443/tcp
检查:
which dotnet
通常位于:
/usr/bin/dotnet
查看日志:
journalctl -u webapi -n 100
或者:
dotnet WebApi.dll
直接查看异常信息。
检查监听:
ss -lntp | grep 5000
检查防火墙:
firewall-cmd --list-ports
或者:
ufw status
使用 Nginx 作为反向代理。
开启 HTTPS。
使用 Systemd 托管进程。
配置日志轮转。
开启自动重启。
定期备份配置文件和应用程序。
建议单独创建运行账户,避免使用 root 用户运行服务。
售前咨询
售后咨询
备案咨询
二维码

TOP