【发布时间】:2018-06-20 19:00:20
【问题描述】:
我使用python-telegram-bot 库开发了一个 Telegram 机器人,现在我想将它部署在我的服务器中,所以我设置了一个 webhook(遵循Official Wiki)但是当我尝试与我的机器人通信时我没有得到任何答复。
这是机器人的来源:
def main():
PRIVTOKEN = "1134xxxx"
updater = Updater(PRIVTOKEN)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
# ...
updater.start_webhook(listen='127.0.0.1',
port=8843,
url_path=PRIVTOKEN)
updater.bot.set_webhook(webhook_url='https://example.com/' + PRIVTOKEN,
certificate=open("cert.pem", "rb"))
print("bot started")
updater.idle()
nginx 配置文件:
server {
listen 443 ssl;
server_name example.com;
location /1134xxxx {
proxy_pass http://127.0.0.1:8443;
}
}
netstat 状态:
sudo netstat -an | grep 8843
tcp 0 127.0.0.1:8843 0.0.0.0:* LISTEN
机器人(我已启用错误日志)或 nginx(access/error.log)没有记录其他错误
我还在防火墙中为 8843 端口添加了自定义规则。
【问题讨论】:
-
请重新检查您的描述 - 您的 python 应用程序侦听 8843,但 nginx 代理到端口 8443(netstat 很烂,我建议使用 lsof -i :8443)
-
修复这个拼写错误也不起作用
-
我没说会有帮助,我只是想清楚地了解情况。请更新初始描述。然后我建议逐跳检查:确保您的数据包可以到达 Nginx,然后确保来自 Nginx 的数据包可以到达您的应用程序。例如,您可以使用 tcpdump 或使用某种日志记录(包括 nginx 日志)
-
尝试向您的服务器添加一个letsencrypt免费https证书
标签: python nginx telegram-bot python-telegram-bot