优化更新反代Telegram Bot API文档
This commit is contained in:
parent
4a6d3e80d0
commit
d5a754ffff
@ -121,14 +121,14 @@ function getGuideSidebarZhCN() {
|
||||
{
|
||||
text: '常见问题',
|
||||
items: [
|
||||
{ text: 'TG api 被墙', link: '/guide/q1.html' },
|
||||
{ text: '反向代理 Telegram API', link: '/guide/q1.html' },
|
||||
{ text: 'Agent 启动/上线 问题自检流程', link: '/guide/q2.html' },
|
||||
{ text: '反向代理 gRPC 端口', link: '/guide/q3.html' },
|
||||
{ text: '实时通道断开/在线终端连接失败', link: '/guide/q4.html' },
|
||||
{ text: '面板数据迁移、备份和恢复', link: '/guide/q5.html' },
|
||||
{ text: '设置每月重置流量统计', link: '/guide/q6.html' },
|
||||
{ text: '自定义 Agent 监控项目', link: '/guide/q7.html' },
|
||||
{ text: '使用Cloudflare Access作为OAuth2提供方', link: '/guide/q8' },
|
||||
{ text: '使用 Cloudflare Access 作为 OAuth2 提供方', link: '/guide/q8' },
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -148,7 +148,7 @@ function getCaseSidebarZhCN() {
|
||||
text: '社区项目',
|
||||
items: [
|
||||
{ text: '1. 搭建哪吒 Telegram 机器人', link: '/case/case1.html' },
|
||||
{ text: '2. 使用Siri语音运行快捷指令查询服务器状态', link: '/case/case2.html' },
|
||||
{ text: '2. 使用 Siri 语音运行快捷指令查询服务器状态', link: '/case/case2.html' },
|
||||
{ text: '3. 自建多用户多语言 Telegram 服务器状态查询机器人', link: '/case/case3.html' },
|
||||
{ text: '4. Fake-agent,监控数据作弊器', link: '/case/case4.html' },
|
||||
{ text: '5. 使用 Argo 隧道的哪吒服务端', link: '/case/case5.html' }
|
||||
|
106
docs/guide/q1.md
106
docs/guide/q1.md
@ -1,67 +1,83 @@
|
||||
## 准备工作
|
||||
**你可以选择 CloudFlare 的 workers 进行反代,但大陆的网络你懂的,这里介绍用你自己服务器反代方式**
|
||||
搭建一个 TGbot api 反代,你需要:
|
||||
1.一个不受 GFW 封锁的服务器(且安装好 Nginx)
|
||||
2.一个域名(提前申请 SSL 证书)
|
||||
<br/>
|
||||
|
||||
如果你的 Dashboard 服务器无法访问 Telegram Bot API,但你依然想使用 Telegram 来推送通知,你可以尝试使用反向代理的方式解决这个问题。
|
||||
|
||||
**这里介绍使用你自己的服务器进行反代的方法。你也可以选择使用 Cloudflare 的 Workers 进行反代,但可能对于中国大陆的用户来说网络连通性依然不佳。**
|
||||
|
||||
要搭建一个 Telegram Bot API 反代,你需要准备以下内容:
|
||||
|
||||
1. 一个可以连接 Telegram Bot API 服务器(并安装好 Nginx)。
|
||||
2. 一个域名(提前申请 SSL 证书)。
|
||||
|
||||
## NGINX 配置
|
||||
编辑你 Nginx 的配置文件,在 http{} 中加上如下配置
|
||||
|
||||
编辑 Nginx 配置文件,在 `http{}` 中添加如下配置:
|
||||
|
||||
```nginx
|
||||
# http强制跳转到htpps
|
||||
# HTTP 强制跳转到 HTTPS
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name yourDomainName;
|
||||
server_name <yourDomainName>;
|
||||
|
||||
# Enforce HTTPS
|
||||
# 强制 HTTPS
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
## https
|
||||
|
||||
# HTTPS 配置
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
server_name <yourDomainName>;
|
||||
|
||||
server_name yourDomainName;
|
||||
# SSL 证书路径
|
||||
ssl_certificate </path/to/your/server.pem>;
|
||||
ssl_certificate_key </path/to/your/server.key>;
|
||||
|
||||
## ssl密钥路径自己改改
|
||||
ssl_certificate server.pem;
|
||||
ssl_certificate_key server.key;
|
||||
# Root 非必要
|
||||
root /var/www/tgbot/;
|
||||
|
||||
## root非必要
|
||||
root /var/www/tgbot/;
|
||||
# 必须配置 DNS,否则会报 502 错误
|
||||
resolver 8.8.8.8;
|
||||
|
||||
## 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;
|
||||
}
|
||||
|
||||
## 以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;
|
||||
}
|
||||
|
||||
## 和上面root一样非必要,这个主要是用来确认服务器状态的。也可以改成return 403
|
||||
location /{
|
||||
try_files /$uri $uri /index.html;
|
||||
}
|
||||
|
||||
## no log no fix
|
||||
error_log /var/log/tg.log error;
|
||||
# 错误日志
|
||||
error_log /var/log/tg.log error;
|
||||
}
|
||||
```
|
||||
`yourDomainName` - 你准备的域名
|
||||
`ssl_certificate` - SSL 证书路径
|
||||
`ssl_certificate_key` - SSL 证书路径
|
||||
<br/>
|
||||
|
||||
- `yourDomainName`:你准备的域名
|
||||
- `ssl_certificate`:SSL 证书路径
|
||||
- `ssl_certificate_key`:SSL 证书路径
|
||||
|
||||
## 使用方式
|
||||
:tada:然后执行 `systemctl restart nginx` 回到 Nezha 将原来的https://api.telegram.org/ 替换为 https://yourDomainName/ ,即可正常推送消息
|
||||
<br/>
|
||||
## 防止盗用
|
||||
`serverIp` - Agent 的 ip 地址,你系统安装的哪个就用哪个命令,ufw iptables 都可.
|
||||
|
||||
执行 `systemctl restart nginx` 重启 Nginx。然后在 Nezha 中将原来的 `https://api.telegram.org/` 替换为 `https://<yourDomainName>/`,即可正常推送消息。
|
||||
|
||||
## 防止盗用
|
||||
|
||||
配置防火墙以防止他人盗用你的反代服务:
|
||||
|
||||
- `serverIp`:Agent 的 IP 地址。根据你的系统选择适用的命令,`ufw` 或 `iptables` 均可。
|
||||
|
||||
```bash
|
||||
#ubuntu
|
||||
ufw allow proto tcp from serverIp to any port 443
|
||||
#centos
|
||||
# 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
|
||||
iptables -I INPUT -s <serverIp> -p tcp --dport 443 -j ACCEPT
|
||||
```
|
||||
|
||||
通过以上配置,可以有效防止未经授权的访问。
|
Loading…
x
Reference in New Issue
Block a user