Nginx Client Closed Request
The HTTP 499 error in Nginx indicates that the client (e.g., a browser or application) closed its connection to the server before Nginx could send a full response. This is not a standard HTTP status code but is specific to Nginx.
Common Causes
- Client-side timeout: The user closed the browser tab, stopped the request, or the client application's timeout is shorter than the server's processing time.
- Slow upstream response: The backend server (e.g., PHP-FPM, Node.js, an API) is taking too long to process the request, causing the impatient client to disconnect.
- Network issues: Unstable connections, proxies, or load balancers between the client and server may drop the request.
How to Fix
1 Increase Proxy Timeouts
Increase the timeout values for communication between Nginx and your upstream (backend) server to prevent Nginx from giving up on a slow backend before the client does.
$ location /your-app/ {
proxy_pass http://backend_server;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s; # Or higher (e.g., 300s)
} 2 Adjust Keepalive Timeout
Reduce the `keepalive_timeout` on the server block to close idle connections faster, which can sometimes help with resource management for impatient clients.
$ server {
listen 80;
server_name example.com;
keepalive_timeout 15s; # Default is 75s
...
} 3 Debug with Logs and $request_time
Log the `$request_time` variable to identify slow requests that correlate with 499 errors. This helps confirm if upstream slowness is the root cause.
$ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $request_time';
access_log /var/log/nginx/access.log main; 4 Optimize Backend Application
If logs show high `$request_time`, investigate and optimize the slow backend application (database queries, external API calls, inefficient code).
$ # Example: Check for slow queries in your app
# This is application-specific. For a PHP app, you might:
# 1. Enable slow query log in MySQL.
# 2. Use a profiler like Xdebug or Blackfire.