CentOS7 下部署 .Net Core+Nginx

记录在centos7 下 .NetCore+Nginx 部署简单过程,供参考。

安装DotNet SDK 官方文档

添加镜像订阅

rpm --import https://packages.microsoft.com/keys/microsoft.asc

sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl= https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo'

安装SDK

sudo yum install libunwind libicu
sudo yum install dotnet-sdk-2.1.3

查看安装

dotnet --version

上传站点 官方文档

psftp [主机地址]

put D:\website.7z

解压文件,使用的是 p7zip

7za x website.7z

创建服务

vi /etc/systemd/system/website.service
[Unit]
Description=Web API Application running on CentOS

[Service]
WorkingDirectory=/home/website
ExecStart=/usr/bin/dotnet /home/website/website.dll
Restart=always
RestartSec=10 # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=website
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

启动服务

systemctl start website systemctl enable website

测试站点

curl localhost:8010

安装Nginx

yum install -y nginx

启动,测试

systemctl start nginx nginx -v

修改配置文件

cd /etc/nginx

vi /etc/nginx/conf.d/vhost_website.conf
server {
    server_name [test.xxx.com];
    root         /home/website;

    location / {
        proxy_pass http://localhost:8010;
    }
}

重新加载

systemctl restart nginx

浏览器打开

http://[test.xxx.com]

其它异常

1.Unable to bind to http://localhost:5000 on the IPv6 loopback interface: ‘Error -99 EADDRNOTAVAIL address not available’.

添加hosting.json

{
  "server.urls": "http://*:8010" }

修改Program

public static void Main(string[] args)
{
    var config = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("hosting.json", optional: true)
        .Build();

    WebHost.CreateDefaultBuilder(args)
        .UseConfiguration(config)
        .UseStartup()
        .Build()
        .Run();
}

本文标题:CentOS7 下部署 .Net Core+Nginx
链接地址:http://www.mswzjz.cn/qtweb/news16/388666.html

攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能