最近用.NET6 开发了一个简单的小程序服务端,做过小程序的应该清楚,小程序请求接口需要协议的地址。
HTTPS
大家都知道,在没有在启动时指定端口或没有在配置时,默认是HTPP协议的5000端口
![](http://dingyue.ws.126.net/2022/0321/61f076b6j00r936w0000tc000qa009cm.jpg)
![](http://dingyue.ws.126.net/2022/0321/1b196aacj00r936w0000zc000ic00bxm.jpg)
在以前,我一般也是才用默认的配置,然后,在前面在启一个nginx来开启协议。我想了一下,就一个简单的查询小程序,没必要又加一层负载。所以,便跟着官网来进行配置
HTTPS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
},
"HttpsInlineCertFile": {
"Url": "https://localhost:5001",
"Certificate": {
"Path": "
"Password": "
},
"HttpsInlineCertAndKeyFile": {
"Url": "https://localhost:5002",
"Certificate": {
"Path": "
"KeyPath": "
"Password": "
",
",
",
在中,我们可以同时为我们的Web服务配置和两个,在配置之前,我们需要准备好所需的证书,这里可以选择证书或者是证书,在证书的压缩包内,会有文件和密码;证书的压缩包内则有和两个文件。
![](http://dingyue.ws.126.net/2022/0321/0d8fea79p00r936w00006c000hq0040m.png)
![](http://dingyue.ws.126.net/2022/0321/fd63c50aj00r936w0000ac0009v004rm.jpg)
我选择的是证书,具体配置如下图,
Nginx
![](http://dingyue.ws.126.net/2022/0321/ba225732j00r936w0002pc000se00k3m.jpg)
看启动的信息,貌似是万事俱备,只欠调用了,可是当我用访问时,它给了我一个惊喜-
https
无法访问
![](http://dingyue.ws.126.net/2022/0321/f09e049bj00r936w0000ec000i400b6m.jpg)
难道是不支持这样配置。我便继续看了看官网的文档,
Kestrel
https
![](http://dingyue.ws.126.net/2022/0321/6281fc46j00r936w0002dc000xr00idm.jpg)
看样子,是我少了一行配置,还需要加上
"SslProtocols": ["Tls12", "Tls13"],
![](http://dingyue.ws.126.net/2022/0321/68050c2dj00r936w0002kc000qs00k5m.jpg)
OK,这样一来,便能通过和来访问我们的了
http
https
Kestrel Web服务
![](http://dingyue.ws.126.net/2022/0321/a73b8d78j00r936w10049c001c200pnm.jpg)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:80"
},
"HttpsInlineCertAndKeyFile": {
"Url": "https://*:443",
"SslProtocols": ["Tls12", "Tls13"],
"Certificate": {
"Path": "C:\\cert\\7430172_domain_nginx\\7430172_domain.com.pem",
"KeyPath": "C:\\cert\\7430172_domain.com_nginx\\7430172_domain.com.key"
热门跟贴