温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nginx怎么将DoNetCore部署到阿里云

发布时间:2022-04-26 17:17:16 来源:亿速云 阅读:214 作者:iii 栏目:大数据

本篇内容主要讲解“Nginx怎么将DoNetCore部署到阿里云”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Nginx怎么将DoNetCore部署到阿里云”吧!

基础环境配置

域名和服务器请先自行购买

基于 云服务器ecs 创建一个应用实例,选择系统镜像为 ubuntu 16.04,在本机通过 ssh 进行远程连接,并进行相关配置
ssh

...

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

配置 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;
 }
}

检测配置并更新

sudo nginx -t
sudo nginx -s reload

安装 dotnetcore

请参考官网最新安装说明:.netcore download

部署流程

打开 visualstudio2017 右键要发布的项目,点击 publish,并参考下图进行相关配置。

Nginx怎么将DoNetCore部署到阿里云

Nginx怎么将DoNetCore部署到阿里云

点击 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部署到阿里云”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI