Fix Tengine upstream timeout for slow MySQL query
2026-09-29
AdSense Slot
When backend SpringBoot runs slow MySQL query, Tengine will throw upstream timeout error to client.
Default timeout values are short
Default proxy_read_timeout is only 60 seconds. If your SQL query takes longer, Tengine cut connection.
Adjust proxy timeout
location /slow-api {
proxy_pass http://springboot-backend;
proxy_connect_timeout 120s;
proxy_read_timeout 180s;
proxy_send_timeout 180s;
}
Warning: Do not set extremely large timeout blindly, better optimize SQL query first.
Debug
Check Tengine error log, look for upstream timed out.
Better practice
- Optimize MySQL index to reduce query execution time (preferred solution)
- Use async task for heavy database job
- Increase timeout only for specific slow API endpoints, not global config
Summary
Timeout adjustment is temporary workaround. Optimizing slow MySQL query should be your priority fix.
AdSense Slot