Reputation: 11
I am using Nginx as a reverse proxy to forward requests to Telegram Bot API in order to reduce rate-limiting on my server. My Nginx configuration works fine when I only proxy to my local Bot API server, but I encounter intermittent timeouts when I include the Telegram server in the upstream configuration or leave it as the only proxy.
Here is my Nginx configuration:
upstream telegram_servers {
server 127.0.0.1:443;
server api.telegram.org:443;
}
server {
listen 80;
server_name my server ip;
location ~* ^/bot\d+:[a-zA-Z0-9_-]+/getUpdates {
proxy_pass https://127.0.0.1:443;
proxy_set_header Host api.telegram.org;
proxy_ssl_server_name on;
proxy_ssl_name api.telegram.org;
proxy_ssl_protocols TLSv1.2 TLSv1.3;
proxy_connect_timeout 60s;
proxy_read_timeout 120s;
proxy_send_timeout 60s;
}
location /bot {
proxy_pass https://telegram_servers;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 60s;
proxy_read_timeout 120s;
proxy_send_timeout 60s;
proxy_ssl_server_name on;
proxy_ssl_name api.telegram.org;
proxy_ssl_protocols TLSv1.2 TLSv1.3;
}
}
When I only proxy to my local Bot API server (127.0.0.1:443), everything works fine with no issues. The problem arises when I add api.telegram.org as the second server in the upstream telegram_servers block or if I leave only Telegram’s API server as the proxy target. I have confirmed there are no network issues on the server and the configuration works in general when proxying to my local Bot API. Error Log: When I try to proxy to the Telegram Bot API, I see the following error intermittently in the Nginx logs:
[error] 317715#317715: *5 upstream timed out (110: Connection timed out) while connecting to upstream, client: <client-ip>, server: my server ip, request: "POST /botXXXX/getMe HTTP/1.1", upstream: "https://149.154.167.220:443/botXXXX/getMe", host: "my server ip"
The error message indicates a connection timeout to Telegram's API server. This occurs only when Telegram's API server is included in the upstream block or as the only proxy.
Any suggestions on what could be causing the intermittent timeouts when adding or using Telegram’s API server, and how to resolve it? Thank you in advance!
What did you try and what were you expecting? I have tried the following:
I configured the Nginx server to proxy requests to both my local Bot API server and the Telegram API server. I set appropriate timeouts (proxy_connect_timeout, proxy_read_timeout, proxy_send_timeout) in the Nginx configuration. I verified that the server itself is not experiencing any network issues, and confirmed that the local Bot API server works fine. I tested the configuration with both my local Bot API server and Telegram's API server, but when I added Telegram's API server to the upstream configuration or left it as the only proxy target, I encountered intermittent timeouts. I was expecting that with these configurations, Nginx would successfully proxy requests to both my local Bot API server and the Telegram API without any issues, and that timeouts would not occur.
Upvotes: 1
Views: 27