nginx部署.net core站点的方法

步骤

aspnetcore程序端口号5001,实际外部端口号8001,相当于把8001收到的请求转发给5001.

把发布出来的文件全部丢掉 /var/www/JuXiangTou 里面去。可以用scp命令或者winscp客户端

  1. centos 7.x
  2. aspnet core 的运行环境,不需要装sdk,一般sdk里面是包含runtime的
 yum install libunwind libicu
yum install aspnetcore-runtime-2.1

nginx,一个反向代理服务,把过来的http请求转发给实际的aspnetcore处理

sudo yum install epel-release
sudo yum install nginx
sudo systemctl start nginx
sudo systemctl enable nginx 

装好nginx要配置端口之类的。

 cd /etc/nginx/ 

nginx.conf是默认的配置文件,基本不用动。

 cd conf.d
vim kestrel-juxiangtou.conf 

下面主要就是两个端口号的需要改一下,其他都可以不用改动。

server {
    listen 8001;
    location / {
        proxy_pass http://localhost:5001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
    }
} 

保存退出

验证一下配置,然后重新载入

sudo nginx -t 
sudo nginx -s reload 

防火墙firewall-cmd。不一定装过,要看环境。

systemctl status firewalld
firewall-cmd --zone=public --add-port=8001/tcp --permanent
firewall-cmd --reload
systemctl restart firewalld.service 

建一个服务,用于维护dotnetcore的程序进程

cd /etc/systemd/system
vim kestrel-juxiangtou.service

 

[Unit]
Description=JuXiangTou

[Service]
WorkingDirectory=/var/www/JuXiangTou
ExecStart=/usr/bin/dotnet /var/www/JuXiangTou/Site.WebApi.dll
Restart=always
RestartSec=10
SyslogIdentifier=JuXiangTou
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target 

保存退出

systemctl restart kestrel-juxiangtou.service 

重启一下服务。

配置一下阿里云的网络安全组里面的端口

参考资料

 http://www.projectcodify.com/hosting-aspnet-core-on-linux-using-nginx

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。