linuxsir首页 LinuxSir.Org | Linux、BSD、Solaris、Unix | 开源传万世,因有我参与欢迎您!
网站首页 | 设为首页 | 加入收藏
您所在的位置:主页 > Limux发行版SuSE >

CentOS7 下部署 .Net Core+Nginx

时间:2018-01-01  来源:未知  作者:admin666

记录在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<Startup>()
        .Build()
        .Run();
}

下面关于Nginx的文章您也可能喜欢,不妨参考下:

Nginx 403 forbidden的解决办法  http://www.linuxidc.com/Linux/2017-08/146084.htm

CentOS 7下Nginx服务器的安装配置  http://www.linuxidc.com/Linux/2017-04/142986.htm

CentOS上安装Nginx服务器实现虚拟主机和域名重定向  http://www.linuxidc.com/Linux/2017-04/142642.htm

CentOS 6.8 安装LNMP环境(Linux+Nginx+MySQL+PHP)  http://www.linuxidc.com/Linux/2017-04/142880.htm

Linux下安装PHP环境并配置Nginx支持php-fpm模块  http://www.linuxidc.com/Linux/2017-05/144333.htm

Nginx服务的SSL认证和htpasswd认证  http://www.linuxidc.com/Linux/2017-04/142478.htm

Ubuntu 16.04上启用加密安全的Nginx Web服务器  http://www.linuxidc.com/Linux/2017-07/145522.htm

Linux中安装配置Nginx及参数详解  http://www.linuxidc.com/Linux/2017-05/143853.htm

Nginx日志过滤 使用ngx_log_if不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

CentOS 7.2下Nginx+PHP+MySQL+Memcache缓存服务器安装配置  http://www.linuxidc.com/Linux/2017-03/142168.htm

CentOS6.9编译安装Nginx1.4.7  http://www.linuxidc.com/Linux/2017-06/144473.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

友情链接