import{_ as s,o as a,c as n,R as l}from"./chunks/framework.44fd0451.js";const F=JSON.parse('{"title":"","description":"","frontmatter":{},"headers":[],"relativePath":"guide/q1.md","filePath":"guide/q1.md","lastUpdated":1715651890000}'),p={name:"guide/q1.md"},o=l(`
如果你的 Dashboard 服务器无法访问 Telegram Bot API,但你依然想使用 Telegram 来推送通知,你可以尝试使用反向代理的方式解决这个问题。
这里介绍使用你自己的服务器进行反代的方法。你也可以选择使用 Cloudflare 的 Workers 进行反代,但可能对于中国大陆的用户来说网络连通性依然不佳。
要搭建一个 Telegram Bot API 反代,你需要准备以下内容:
编辑 Nginx 配置文件,在 http{}
中添加如下配置:
# HTTP 强制跳转到 HTTPS
server {
listen 80;
listen [::]:80;
server_name <yourDomainName>;
# 强制 HTTPS
return 301 https://$server_name$request_uri;
}
# HTTPS 配置
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name <yourDomainName>;
# SSL 证书路径
ssl_certificate </path/to/your/server.pem>;
ssl_certificate_key </path/to/your/server.key>;
# Root 非必要
root /var/www/tgbot/;
# 必须配置 DNS,否则会报 502 错误
resolver 8.8.8.8;
# 以 /bot 开头的请求会被正则匹配
location ~* ^/bot {
proxy_buffering off;
proxy_pass https://api.telegram.org$request_uri;
proxy_http_version 1.1;
}
# Root 非必要,主要用于确认服务器状态。也可以改为 return 403
location / {
try_files $uri $uri /index.html;
}
# 错误日志
error_log /var/log/tg.log error;
}
yourDomainName
:你准备的域名ssl_certificate
:SSL 证书路径ssl_certificate_key
:SSL 证书路径执行 systemctl restart nginx
重启 Nginx。然后在 Nezha 中将原来的 https://api.telegram.org/
替换为 https://<yourDomainName>/
,即可正常推送消息。
配置防火墙以防止他人盗用你的反代服务:
serverIp
:Agent 的 IP 地址。根据你的系统选择适用的命令,ufw
或 iptables
均可。# Ubuntu
ufw allow proto tcp from <serverIp> to any port 443
# CentOS
iptables -I INPUT -p tcp --dport 443 -j DROP
iptables -I INPUT -s <serverIp> -p tcp --dport 443 -j ACCEPT
通过以上配置,可以有效防止未经授权的访问。
`,16),e=[o];function t(c,r,C,y,D,A){return a(),n("div",null,e)}const d=s(p,[["render",t]]);export{F as __pageData,d as default};