nginx - 无法在 Telegram bot webhook 中使用 Let's Encrypt 证书(自签名证书工作正常)

标签 nginx telegram telegram-bot lets-encrypt telegram-webhook

我正在尝试使用 Let's Encrypt 证书 设置我的 Telegram bot webhook,但 Telegram 一直说verification_failed。但是,浏览器完全可以使用新的 Let's Encrypt 证书。

我的自签名证书目前在我的 Ubuntu 17.04Nginx 网络服务器 上的 webhook 中正常工作。

我错过了什么?

当前的自签名证书设置(有效)

我使用这个命令生成了我的证书:

openssl req -newkey rsa:2048 -sha256 -nodes -keyout my-cert.key -x509 -days 365 -out my-cert.pem -subj "/C=CA/ST=Ontario/L=Toronto/O=My Organization/CN=example.org"

和 Nginx 配置:

server {
    server_name example.org www.example.org localhost;

    listen 443  ssl;
    listen 8080 ssl;
    listen 8443 ssl;

    ssl_certificate     /etc/nginx/certificates/my-cert.pem;
    ssl_certificate_key /etc/nginx/certificates/my-cert.key;

    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
    ssl_prefer_server_ciphers on;

    location ~* ^/bots/mybot/webhook/.+$ {
        proxy_pass          http://0.0.0.0:5000;
        proxy_http_version  1.1;
        proxy_set_header    Upgrade $http_upgrade;
        proxy_set_header    Connection keep-alive;
        proxy_set_header    Host $host;
        proxy_cache_bypass  $http_upgrade;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

新的 Let's Encrypt 设置(在浏览器中有效,在 webhook 中失败)

证书是使用 EFF 的优秀 certbot 为我的域生成的。

设置 Telegram 的 webhook 时,我使用 /etc/letsencrypt/live/example.org/cert1.pem 文件。

这是我试过的 Nginx 配置:

server {
    server_name example.org www.example.org localhost;

    listen  80;
    listen  [::]:80;

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    }
}

server {
    server_name example.org www.example.org localhost;

    listen 443  ssl;
    listen 8080 ssl;
    listen 8443 ssl;

    ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem; # managed by Certbot

    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
    ssl_prefer_server_ciphers on;

    location ~* ^/bots/mybot/webhook/.+$ {
        proxy_pass          http://0.0.0.0:5000;
        proxy_http_version  1.1;
        proxy_set_header    Upgrade $http_upgrade;
        proxy_set_header    Connection keep-alive;
        proxy_set_header    Host $host;
        proxy_cache_bypass  $http_upgrade;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

最佳答案

我不久前自己用 Apache 网络服务器尝试过这个,但在 Ubuntu 17.04 上也用 letsencrypt 并且它工作正常。

您提到您使用了带有附加参数(传递证书...)的 setwebhook?url= 方法。不知何故,这是不需要的。您只需输入以 https:// 开头的 url 就可以了。

关于nginx - 无法在 Telegram bot webhook 中使用 Let's Encrypt 证书(自签名证书工作正常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44885229/

相关文章:

在 Kubernetes 中调试 uWSGI

python - Telegram 类型错误 : the first argument must be callable

python - 使用 python-telegram-bot 进行语音识别,无需下载音频文件

javascript - 通过 node.js 的 Telegram Bot Live Location

java - 电报Bot gradle.build配置

linux - 尝试RUN时Openresty Docker容器,返回nginx : invalid option: "/bin/sh"

php - Nginx 不会将 Cookie 传递给代理

nginx - 简单的 nginx 反向代理似乎剥离了一些 header

python - Telegram webhooks POST 请求的负载为空

Telegram 可以通过 id 聊天,不能通过 @name : Chat not found