.NET 反向代理-YARP 部署Https(SSL)
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:
Certificateconfigures the certificate source.Protocolsconfigures the allowed HTTP protocols.SslProtocolsconfigures the allowed SSL protocols.ClientCertificateModeconfigures 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
.NET 反向代理-YARP 部署Https(SSL)的更多相关文章
- .NET 反向代理-YARP 根据域名转发
前段时间发布过一个关于 YARP 的简单介绍,感兴趣的小伙伴恭请移步看看 .NET 反向代理-YARP - 一事冇诚 - 博客园 (cnblogs.com) 作为反向代理,必不可少的当然是根据域名代理 ...
- haproxy反向代理环境部署(http和https代理)
操作背景:前方有一台haproxy代理机器(115.100.120.57/192.168.1.7),后方两台realserver机器(192.168.1.150.192.168.1.151,没有公网i ...
- .NET 反向代理-YARP
什么是 YARP YARP (另一个反向代理) 设计为一个库,提供核心代理功能,你可以根据应用程序的特定需求进行自定义. YARP 是使用 .NET的基础架构构建在 .NET上的.YARP 的主要不同 ...
- nginx反向代理批量实现https协议访问
我们进入大多数HTTPS网站ie浏览器都会给出相关提醒了,但我配置了一台HTTPS代理机器发现css与js都加载不了,这个有朋友说是https页面,如果加载http协议的内容,会被认为页面不安全,所以 ...
- nginx反向代理+负载均衡+https
A服务器(192.168.133.1)作为nginx代理服务器 B服务器(192.168.133.2)作为后端真实服务器 访问https://www.test.com请求从A服务器上反向代理到B服务器 ...
- Nginx安装配置|Nginx反向代理|Nginx支持HTTPS|Nginx重定向
Nginx安装配置 可以直接看到最下面的HTTPS. Nginx安装 我的系统如下: No LSB modules are available. Distributor ID: Ubuntu Desc ...
- .NET 反向代理 YARP 跨域请求 CORS
使用过 nginx 的小伙伴应该都知道,这个中间件是可以设置跨域的,作为今天的主角,同样的 反向代理中间件的 YARP 毫无意外也支持了跨域请求设置. 有些小伙伴可能会问了,怎样才算是跨域呢? 在 H ...
- .NET 反向代理 YARP 通过编码方式配置域名转发
前面介绍了 YARP 通过配置文件的方式配置代理转发(传送门),而众所周知,微软的一贯作风就是能通过配置文件做的事情,通过编码的方式也能实现!YARP 也不例外,废话不多说,直接上代码! 首先,参照官 ...
- .NET 反向代理 YARP 自定义配置提供程序(Configuration Providers)
介绍 基本 Yarp 示例显示从 appsettings.json 加载的代理配置.相反,代理配置可以从您选择的源以编程方式加载.您可以通过提供几个实现 IProxyConfigProvider 和 ...
随机推荐
- Cayley 定理与扩展 Cayley 定理
Cayley 定理 节点个数为 \(n\) 的无根标号树的个数为 \(n^{n−2}\) . 这个结论在很多计数类题目中出现,要证明它首先需要了解 \(\text{Prufer}\) 序列的相关内容. ...
- 从解析HTML开始,破解页面渲染时间长难题
摘要:在本文中,将重点关注网页的初始渲染,即它从解析 HTML 开始. 我将探索可能导致高渲染时间的问题,以及如何解决它们. 本文分享自华为云社区<页面首屏渲染性能指南>,作者:Ocean ...
- 【Azure 存储服务】Hadoop集群中使用ADLS(Azure Data Lake Storage)过程中遇见执行PUT操作报错
问题描述 在Hadoop集中中,使用ADLS 作为数据源,在执行PUT操作(上传文件到ADLS中),遇见 400错误[put: Operation failed: "An HTTP head ...
- Nginx配置解决NetCore的跨域
使用Nginx配置解决NetCore的跨域 废话不多说,直接上Nginx配置 server { listen 80; server_name 你的Id或域名; location / { add_hea ...
- php和js的不定参
function my_func() { $args = func_get_args(); print_r($args); } my_func('php','java','node.js'); jav ...
- vue-resource && axios
1 # axios 2 # 1.安装:npm i axios 3 # 2.使用: 4 import axios from 'axios' 5 axios.get(URL).then(response= ...
- Java学习 (七)基础篇 变量
变量 变量顾名思义,就是可以变化的量 Java是一种强类型语言,每个变量都必须声明其类型 Java变量是程序中最基本的存储单位,其要素包括变量名.变量类型和作用域 type varName [=val ...
- Educational Codeforces Round 132 (Rated for Div. 2)
Educational Codeforces Round 132 (Rated for Div. 2) A. Three Doors 简述 题意: 有三扇门(1~3), 其中两扇门后面有对应标号门的钥 ...
- 使用 for 循环 打印 9X9乘法表
C 语言自学之99乘法表 请使用for循环,倒序打印9*9乘法表 1 #include <stdio.h> 2 3 int main() 4 { 5 int i,j,result;//定义 ...
- LuoguP2953 [USACO09OPEN]牛的数字游戏Cow Digit Game(博弈论)
1~9显然,后面平\(A\)过去 #include <iostream> #include <cstdio> #include <cstring> #include ...