全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1166|回复: 5

[Windows VPS] 如何配置 Nginx Python-Telegram-Bot WebHook

[复制链接]
发表于 2021-3-17 12:21:57 | 显示全部楼层 |阅读模式
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks

Using nginx with one domain/port for all bots

All bots set their url to the same domain and port, but with a different url_path.

The integrated server should usually be started on the localhost or 127.0.0.1 address, the port can be any port you choose.

Note: example.com could be replaced by an IP address, if you have no domain associated to your server.

Example code to start the bot:

  1. updater.start_webhook(
  2.     listen='127.0.0.1',
  3.     port=5000,
  4.     url_path='TOKEN1',
  5.     webhook_url='https://example.com/TOKEN1',
  6.     cert=open('cert.pem', 'rb')
  7. )
复制代码


Example configuration for nginx (reduced to important parts) with two bots configured:

  1. server {
  2.     listen              443 ssl;
  3.     server_name         example.com;
  4.     ssl_certificate     cert.pem;
  5.     ssl_certificate_key private.key;

  6.     location /TOKEN1 {
  7.         proxy_pass http://127.0.0.1:5000/TOKEN1/;
  8.     }

  9.     location /TOKEN2 {
  10.         proxy_pass http://127.0.0.1:5001/TOKEN2/;
  11.     }
  12. }
复制代码


请问 'cert.pem' 这个文件从哪里来的?
发表于 2021-3-17 12:27:45 | 显示全部楼层
    ssl_certificate     cert.pem;
    ssl_certificate_key private.key;

这两项是域名证书,申请了,把路径地址替换就可以了
 楼主| 发表于 2021-3-18 14:30:39 | 显示全部楼层
不使用Nginx反代,直接起服务器也无法成功。按照网上的教程一直搞不定。
 楼主| 发表于 2021-3-31 08:07:51 | 显示全部楼层
顶一顶,看看有没有大佬指点一下
发表于 2021-3-31 09:21:07 来自手机 | 显示全部楼层
zxxx 发表于 2021-3-18 14:30
不使用Nginx反代,直接起服务器也无法成功。按照网上的教程一直搞不定。

好像必须用NGINX吧,模糊记得需要https才行
 楼主| 发表于 2021-3-31 09:30:25 | 显示全部楼层
Nginx已经配置https可以反代薇儿,但是反代bot,通过网页查询api状态显示SSL错误之类的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-5-11 07:15 , Processed in 0.063608 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表