欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Asp.net core部署 CentOS Linux

程序员文章站 2024-01-04 15:45:58
...

1.添加配置文件
hosting.json

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

2.编辑Program.cs文件,修改为内容如下:

        public static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("hosting.json", optional: true)
                .Build();
 
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseConfiguration(config)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseApplicationInsights()              
                .Build();
 
            host.Run();
        }

3.发布项目
右键项目-发布,选择文件夹模式。
把发布的PublishOutput文件夹压缩成zip格式,上传到CentOS服务器。

$ #解压之前上传的网站压缩文件,如果没有安装unzip,运行yum install -y unzip zip安装
$ unzip ~/dotnet/PublishOutput.zip
$ #先关闭防火墙
$ systemctl stop firewalld.service
$ #启动网站
$ cd PublishOutput
$ dotnet  TestAspNetCoreWeb.dll
$ 如果报错Failed to bind to CoreCLR,运行yum install -y libunwind 和 yum install -y icu
相关标签: net core