How to Debug Slow Nginx/Apache Response Times

A slow website has many possible causes — this guide provides a systematic approach to isolating whether the bottleneck is in the web server, the application, the database, or the network.

Step 1 — Measure Where Time Is Actually Being Spent

curl -w "@curl-format.txt" -o /dev/null -s https://yourdomain.com
# curl-format.txt contents:
time_namelookup:  %{time_namelookup}\n
time_connect:  %{time_connect}\n
time_starttransfer:  %{time_starttransfer}\n
time_total:  %{time_total}\n

Breaks down DNS lookup, connection, and total response time separately — a large gap between connect and starttransfer specifically points to backend/application processing time, not network issues.

Step 2 — Enable Nginx Request Timing in Logs

log_format timing '$remote_addr - $request_time - $upstream_response_time - "$request"';
access_log /var/log/nginx/timing.log timing;

$request_time is total time; $upstream_response_time isolates specifically how long the backend/application took to respond — a large gap between the two suggests Nginx itself (or something between Nginx and the backend) is adding delay.

Step 3 — Check for PHP-FPM Slow Log (If Applicable)

sudo nano /etc/php/8.2/fpm/pool.d/www.conf
slowlog = /var/log/php-fpm-slow.log
request_slowlog_timeout = 3s

Logs full stack traces for any PHP request taking longer than the specified threshold — often reveals the exact slow function/database query directly.

Step 4 — Check Database Query Performance

Slow database queries are among the most common causes of overall application slowness — see database-specific slow query log guides for your specific database to identify and address problematic queries.

Step 5 — Check Server Resource Usage During Slow Periods

htop

Correlate slow response times with actual resource pressure (CPU, RAM, disk I/O) — see How to Monitor Real-Time System Resources with htop and top.

Step 6 — Check Nginx Worker Process Configuration

worker_processes auto;
worker_connections 1024;

See Nginx Performance Tuning: Worker Processes, Caching & Gzip — undersized worker configuration can cause request queuing under load even when the backend itself is fast.

Step 7 — Check for DNS Resolution Delays

If your application makes external API calls, slow DNS resolution for those external services can add unexpected latency — check whether external dependencies are the actual bottleneck rather than your own infrastructure.

Step 8 — Use Distributed Tracing for Multi-Service Architectures

If your application spans multiple services, see How to Implement Distributed Tracing with Jaeger — pinpoints exactly which specific service/call in a complex request chain is responsible for the delay.

Step 9 — Check for Missing Caching

See How to Set Up a Reverse Proxy Cache to Reduce Origin Server Load and How to Set Up FastCGI Caching in Nginx for PHP Applications — often the most impactful fix once the actual bottleneck (repeated, expensive backend processing) is identified.

Common Errors

Site is fast when tested from the server itself but slow for real visitors — points toward a network/CDN/geographic latency issue rather than a server-side processing problem; see How to Diagnose and Fix High Network Latency.

Continue Reading

Browse more articles in Web Servers.

  • debug slow website, nginx response time, php-fpm slow log, website performance troubleshooting
  • 0 用戶發現這個有用
這篇文章有幫助嗎?

相關文章

How to Install Nginx on Ubuntu & Debian (Complete Guide)

Nginx is one of the world's most widely used web servers, known for its speed, low resource...

How to Install Apache on Ubuntu & Debian (Complete Guide)

Apache HTTP Server is one of the most widely used web servers, valued for its stability, flexible...

Nginx Virtual Hosts (Server Blocks): Hosting Multiple Websites on One VPS

Nginx "server blocks" (the equivalent of Apache's virtual hosts) let you host multiple...

Apache Virtual Hosts: Hosting Multiple Websites on One VPS

Apache Virtual Hosts allow a single server to host multiple independent websites, each identified...

How to Configure Nginx as a Reverse Proxy for Node.js/Docker Apps

A reverse proxy sits in front of your application, handling incoming traffic on standard ports...