小编Taw*_*kil的帖子

MailKit.Security.SslHandshakeException:主机名与服务器 SSL 证书中给定的名称不匹配。ASP.NET 核心、Nginx

当我尝试通过 Google 和生产容器化应用程序上的 MailKit 库发送电子邮件时,出现以下异常:

MailKit.Security.SslHandshakeException:尝试建立 SSL 或 TLS 连接时发生错误。主机名与服务器 SSL 证书中给出的名称不匹配。

我使用 ASP.NET Core 5 和 Kestrel。Nginx 是我的反向代理。当我使用 Postman 获取数据时,SSL 工作正常。但是当我尝试发送邮件时,出现异常。在没有 Nginx 服务器的开发环境中,代理可以正常工作。

这是我的 nginx.conf 文件:

server {
    client_max_body_size 6M;

    listen 80;

    server_name myhost.com www.myhost.com;

    server_tokens off;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    client_max_body_size 6M;

    listen 443 ssl;

    server_name myhost.com www.myhost.com;

    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_min_length 0;
    gzip_types …
Run Code Online (Sandbox Code Playgroud)

ssl reverse-proxy nginx mailkit asp.net-core

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-core ×1

mailkit ×1

nginx ×1

reverse-proxy ×1

ssl ×1