码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • .NET 反向代理-YARP 部署Https(SSL)


    合集 - .NET(21)
    1..NET Core 环境搭建2022-03-162..Net Core IOC DI(依赖注入)2022-03-163..NET Core 读取配置技巧 - IOptions 接口2022-05-254..Net Core 依赖注入(IOC) 一些简单的使用技巧2022-05-065..Net Core 可为Null的类型2022-04-026..Net Core 配置文件 appsettings.json2022-03-25
    7..NET 反向代理-YARP 部署Https(SSL)2022-09-21
    8..NET 反向代理-YARP 根据域名转发2022-09-219..NET 7 来了!!!2022-09-1910..NET 反向代理-YARP2022-09-0711..Net Core 配置文件读取 - IOptions、IOptionsMonitor、IOptionsSnapshot2022-09-0212..NET Core 实现后台任务(定时任务)Longbow.Tasks 组件(三)2022-07-2313..NET Core 实现后台任务(定时任务)BackgroundService(二)2022-07-1314..NET Core 实现后台任务(定时任务)IHostedService(一)2022-07-0815..Net WebApi 中的 FromBody FromForm FromQuery FromHeader FromRoute2022-10-0716..NET 反向代理 YARP 代理 GRPC2022-09-2817..Net 7 C#11 原始字符串2022-09-2618..NET 反向代理 YARP 跨域请求 CORS2022-09-2619..NET 反向代理 YARP 自定义配置提供程序(Configuration Providers)2022-09-2520..NET 反向代理 YARP 通过编码方式配置域名转发2022-09-2421..NET 部署 多域名 Https(SSL)通过代码方式2022-09-23
    收起

      YARP 作为反向代理中间件,那就无可避免需要使用到 Https 去部署项目,那 YARP 要怎么去实现呢,本来以为 YARP 会有一套自己的实现,在翻阅了资料后发现,根本不是我想的那样,按照 YARP 官方文档的说法,是按照 .Net Core 原本的那一套去实现,好家伙,真的没想到啊,下面我贴出官方原文,大伙看一看,瞧一瞧

      IIS就不多说了,这个毕竟只能在 windows 上使用,下面我说说 在 Kestrel 怎么设置 Https 吧,按照我的惯例,直接贴配置文件

    复制代码
    "Kestrel": {
      "Endpoints": {
        "MySniEndpoint": {
          "Url": "https://*:5209",
          "SslProtocols": [ "Tls11", "Tls12" ],
          "Sni": {
            "test1.ysmc.net.cn": {
              "Certificate": {
                "Path": "[path]\\test1.ysmc.net.cn_server.pfx",
                "Password": "pfx密码"
              }
            },
            "test2.ysmc.net.cn": {
              "Certificate": {
                "Path": "[path]\\test2.ysmc.net.cn_server.pfx",
                "Password": "pfx密码"
              }
            }
          }
        }
      },
      //,默认配置,当没有配置的时候,默认回落到这个配置   
      "Certificates": {
        "Default": {
          "Path": "[path]\\test1.ysmc.net.cn_server.pfx",
          "Password": "pfx密码"
        }
      }
    复制代码

      因为我们需要配置多个域名,所以使用到了 Sni,下面是官方对一 Sni 的部分介绍,感兴趣的小伙伴可以过去看看,传送门


     

    SNI in configuration

    Kestrel supports SNI defined in configuration. An endpoint can be configured with an object that contains a mapping between host names and HTTPS options. The connection host name is matched to the options and they are used for that connection.Sni

    The following configuration adds an endpoint named that uses SNI to select HTTPS options based on the host name:MySniEndpoint

    HTTPS options that can be overridden by SNI:

    • Certificate configures the certificate source.
    • Protocols configures the allowed HTTP protocols.
    • SslProtocols configures the allowed SSL protocols.
    • ClientCertificateMode configures the client certificate requirements.

    The host name supports wildcard matching:

    • Exact match. For example, matches .a.example.orga.example.org
    • Wildcard prefix. If there are multiple wildcard matches then the longest pattern is chosen. For example, matches and .*.example.orgb.example.orgc.example.org
    • Full wildcard. matches everything else, including clients that aren't using SNI and don't send a host name.*

    The matched SNI configuration is applied to the endpoint for the connection, overriding values on the endpoint. If a connection doesn't match a configured SNI host name then the connection is refused.


     

    下面一起看看配置后的效果吧,非常的完美

     

       整个完整的配置文件我也贴出来吧,至于证书怎么申请的,大家有域名的可以到域名服务商里申请免费1年期的,没有域名的话,可以自己改一下hosts 文件 然后自己自签名一个,都是可以的

    appsettings.json

    复制代码
    {
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft.AspNetCore": "Warning"
        }
      },
      "Kestrel": {
        "Endpoints": {
          "MySniEndpoint": {
            "Url": "https://*:5209",
            "SslProtocols": [ "Tls11", "Tls12" ],
            "Sni": {
              "test1.ysmc.net.cn": {
                "Certificate": {
                  "Path": "[path]\\test1.ysmc.net.cn_server.pfx",
                  "Password": "pfx密码"
                }
              },
              "test2.ysmc.net.cn": {
                "Certificate": {
                  "Path": "[path]\\test2.ysmc.net.cn_server.pfx",
                  "Password": "pfx密码"
                }
              }
            }
          }
        },
        "Certificates": {
          "Default": {
            "Path": "[path]\\test1.ysmc.net.cn_server.pfx",
            "Password": "pfx密码"
          }
        }
      },
      "ReverseProxy": {
        "Routes": {
          "baidu": {
            "ClusterId": "baidu",
            "Match": {
              "Hosts": [ "test1.ysmc.net.cn" ],
              "Path": "{**catch-all}"
            }
          },
          "blazor": {
            "ClusterId": "blazor",
            "Match": {
              "Hosts": [ "test2.ysmc.net.cn" ],
              "Path": "{**catch-all}"
            }
          }
        },
        "Clusters": {
          "baidu": {
            "LoadBalancingPolicy": "RoundRobin",
            "Destinations": {
              "baidu": {
                "Address": "https://www.baidu.com/"
              }
            }
          },
          "blazor": {
            "LoadBalancingPolicy": "RoundRobin",
            "Destinations": {
              "blazor": {
                "Address": "https://www.blazor.zone/"
              }
            }
          }
        }
      }
    }
    复制代码

     原文链接:https://www.cnblogs.com/ysmc/p/16717580.html

  • 相关阅读:
    ES报错1
    Meta Llama 3 简介
    动态内存分配 指针类型转换
    电脑文档数据恢复?别急,一招教你快速找回丢失数据!
    java: 无法访问org.mybatis.spring.annotation.MapperScan
    俄罗斯、乌克兰程序员薪资曝光!年薪 15w+,女程序员比男程序员收入高
    机器学习笔记 - 特斯拉的占用网络简述
    MySQL XA事务文档翻译
    【gogogo专栏】golang并发编程
    codesys TCP客户端程序
  • 原文地址:https://www.cnblogs.com/ysmc/p/16717580.html
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号