码农知识堂 - 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

  • 相关阅读:
    平衡二叉树的 AVL 实现
    【Vue】axios的二次封装和使用(附详细代码)
    如何从命令行CMD、IDEA的终端快速在explorer/finder资源管理器访达中打开对应的目录(Windows、Mac)
    【LLM之RAG】KG_RAG论文阅读笔记
    巨神奇,2013年的老Mac,竟直接装上macOS Ventura 13.1 Beta版
    【排序算法】插入排序(C语言)
    Rust逆向学习 (1)
    深入了解 Axios 的 put 请求:使用技巧与最佳实践
    JAVA计算机毕业设计程序设计类课程的课堂教学效果评价系统Mybatis+系统+数据库+调试部署
    《量子计算:下一个大风口,还是一个热炒概念?》
  • 原文地址:https://www.cnblogs.com/ysmc/p/16717580.html
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号