银河麒麟服务器v10 sp1 部署.Net6.0 http https

上一篇:银河麒麟服务器V10 SP1 .Net6.0 开机自动启动_csdn_aspnet的博客-CSDN博客 

参考微软官网:ASP.NET Core 中的 Kestrel Web 服务器 | Microsoft Learn

为 ASP.NET Core Kestrel Web 服务器配置终结点 | Microsoft Learn 

注意:使用此篇文章配置,请将之前文中的appsettings.json中配置"urls": "http://*:8061" 注释。

json内容,选择适合自己的即可:

{
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5000"
      },
      "HttpsInlineCertFile": {
        "Url": "https://localhost:5001",
        "Certificate": {
          "Path": "<path to .pfx file>",
          "Password": "<certificate password>"
        }
      },
      "HttpsInlineCertStore": {
        "Url": "https://localhost:5002",
        "Certificate": {
          "Subject": "<subject; required>",
          "Store": "<certificate store; required>",
          "Location": "<location; defaults to CurrentUser>",
          "AllowInvalid": "<true or false; defaults to false>"
        }
      },
      "HttpsDefaultCert": {
        "Url": "https://localhost:5003"
      },
      "Https": {
        "Url": "https://*:5004",
        "Certificate": {
          "Path": "<path to .pfx file>",
          "Password": "<certificate password>"
        }
      }
    },
    "Certificates": {
      "Default": {
        "Path": "<path to .pfx file>",
        "Password": "<certificate password>"
      }
    }
  }
}

本文使用的是pfx节点配置。 

在appsettings.json中新增配置:

{
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://xxx:8061"
      },
      "HttpsInlineCertFile": {
        "Url": "https://xxx:8062",
        "Certificate": {
          "Path": "/usr/local/xxx.pfx",
          "Password": "xxx@2023"
        }
      }
    }
  }
}

本文在windows配置示例如下:

上面示例部署到银河麒麟V10 SP1时,更换银河麒麟V10服务器pfx证书的具体路径。

在Program.cs中读取Kestrel配置节点:

代码如下: 

//部署银河麒麟V10 SP1 读取appsettings.json中Kestrel配置
            app.Configuration.Get<WebHostBuilder>().ConfigureKestrel(options =>
            {
                // 长度最好不要设置 null
                options.Limits.MaxRequestBodySize = 1024 * 1024 * 600;
                //获取或设置最大打开的连接数
                options.Limits.MaxConcurrentConnections = 1024;
                //获取或设置最大打开、升级的连接数
                //升级的连接是已从 HTTP 切换到另一个协议(如 WebSocket)的连接。
                //连接升级后,不会计入 MaxConcurrentConnections 限制
                options.Limits.MaxConcurrentUpgradedConnections = 500;

            })
            //银河麒麟V10 SP1 解决无法访问静态文件问题
            .UseContentRoot(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot"));

 重新发布net6项目,并重新启动dotnet6服务即可正常访问:

https访问: 

http访问:

猜你喜欢

转载自blog.csdn.net/hefeng_aspnet/article/details/131552068
今日推荐