Asp.net core部署 CentOS Linux

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章