我正在尝试使用让加密证书设置我的 Telegram bot webhook ,但Telegram一直在说 verification_failed 。然而,使用新的Let's Encrypt证书,浏览器完全没问题。
我的自签名证书目前在 Ubuntu 17.04 上使用 Nginx Web服务器的webhooks中正常工作。
我缺少什么?
我使用此命令生成证书:
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;
}
}
使用EFF的优秀证书机构为我的域名生成证书。
设置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;
}
}
答案 0 :(得分:3)
我前一段时间尝试过使用Apache网络服务器,但是在使用letsencrypt的Ubuntu 17.04上也运行良好。
您提到您使用setwebhook?url=
方法和其他参数(传递证书...)。不知何故,这不是必需的。您只需输入以https://
开头的网址即可。