基础环境准备与连接
基础环境准备
请提前准备好域名及云服务器资源。
在云服务器 ECS 控制台创建应用实例,系统镜像选择 Ubuntu 16.04。随后通过 SSH 协议从本机连接服务器进行后续配置。 ssh root@http://39.108.48.203/
...
sudo apt-get update
sudp apt-get upgrade
sudo apt-get autoremove
sudo apt-get clean
安装与配置 Nginx
sudo apt-get install nginx
sudo service nginx start
sudo gedit /etc/nginx/sites-available/default
编辑 Nginx 的 default 配置文件,在文件末尾添加以下节点信息以设置反向代理规则。
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {
listen 80;
# 网站文件的目标位置
root /home/hippie/website/wwwroot;
# 网站域名
server_name your website name;
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;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
完成配置后,需检测配置语法是否正确并重新加载 Nginx 服务。
sudo nginx -t
sudo nginx -s reload
安装 DotNetCore 运行时
具体安装步骤请参考官网最新说明:.NetCore Download
应用部署流程
在 VisualStudio2026 中右键目标项目,选择“发布”(publish),并根据界面提示进行相应配置。


点击 Save 按钮保存配置并执行发布操作。待 publish 文件夹生成后,将其上传至服务器的指定位置。上传完成后,执行以下命令启动应用:
dotnet run app.dll
若配置无误,此时即可通过服务器 IP 或绑定的网站域名访问该应用。
创建守护进程
上述手动启动方式无法保证程序长时间稳定运行,因此需要借助守护进程来管理网站的生命周期。
sudo apt-get install supervisor
sudo vim /ect/supervisor/conf.d/website.conf
编写 website.conf 配置文件
[program:website]
#要执行的命令
command=/usr/bin/dotnet Attention.dll
#命令执行的目录
directory=/home/hippie/website
#环境变量
environment=ASPNETCORE__ENVIRONMENT=Production
#进程执行的用户身份
user=www-data
stopsignal=INT
#是否自动启动
autostart=true
#是否自动重启
autorestart=true
#自动重启间隔
startsecs=1
#标准错误日志
stderr_logfile=/var/log/website.err.log
#标准输出日志
stdout_logfile=/var/log/website.out.log
配置完成后,执行以下命令以启动守护进程管理服务。
sudo supervisorctl shutdown && sudo supervisord -c /etc/supervisor/supervisord.conf
supervisorctl shutdown
sudo service supervisor start
此时可尝试断开远程连接,再次通过浏览器访问网站。若能正常显示,表明配置生效。
总结
以上所述是小编给大家介绍的结合 Nginx 将 DoNetCore 部署到 阿里云的安装配置方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!