NGINX Error: Incomplete Headers (0 Bytes) Received From Server

Updated: January 20, 2024 By: Guest Contributor Post a comment

The Problem

NGINX is a high-performance web server that is also used as a reverse proxy, load balancer, and HTTP cache. Despite its robustness, encountering errors is not out of the ordinary. One such error is an NGINX response that indicates Incomplete headers (0 bytes) received from server. This tutorial will guide you through the steps to diagnose and resolve this common issue.

Why does it happen?

The ‘Incomplete headers’ error typically occurs when NGINX is configured as a reverse proxy and cannot retrieve a valid HTTP response from the backend server. The 0 bytes indicate that no data has been sent. This can be due to a range of issues, from network problems to backend server crashes.

Steps to Resolve the Error

Step 1: Check NGINX and Backend Server Logs

First, we need to look into the NGINX error logs to gain a better understanding of what might be causing the problem. You can find the logs at /var/log/nginx/error.log.

tail -f /var/log/nginx/error.log

Similarly, check the logs for your backend server to see if it is functioning correctly and logging any related errors.

Step 2: Examine NGINX Configuration

Examine the configuration settings for the reverse proxy in /etc/nginx/nginx.conf or any additional included configuration files. Ensure that the proxy_pass directive is correctly set up to direct requests to the appropriate backend server.

location / {
    proxy_pass http://backend_server;
    ...
}

Check if the proxy_set_header directives are properly configured to pass necessary headers to the backend.

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;

Step 3: Backend Server Health Check

Ensure that the backend server is running and is accessible from the NGINX server. You can use tools like curl to check the backend server’s response directly.

curl -I http://backend_server

If the backend server is down or not responding, you need to resolve these issues before NGINX can serve the content correctly.

Step 4: Network Troubleshooting

If there is a connectivity issue between NGINX and the backend server, you might need to conduct network troubleshooting. Use ping or traceroute to confirm that the network path is clear and without issues.

ping backend_server
traceroute backend_server

Step 5: Review Timeout Settings

In some cases, the error can be caused by timeout settings that are too low for the backend server to respond in time. In your NGINX configuration, look for the proxy_read_timeout directive and consider increasing its value.

proxy_read_timeout 90s;

Also, review timeout settings on your backend server and increase them if necessary.

Step 6: Increase Buffer Sizes

Insufficient buffer sizes in NGINX for handling headers can lead to incomplete headers error. To fix this, you might need to increase buffer sizes in NGINX config files.

proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;

Step 7: Check for Firewall Restrictions

Firewall settings might sometimes block the communication between NGINX and the backend server. Ensure that your firewall allows traffic on the required ports.

Step 8: Update NGINX and Backend Server

If none of the above steps solve the issue, consider updating NGINX and the backend server software to the latest stable versions. You might be encountering a known bug that has been fixed in a more recent release.

To update NGINX:

sudo apt update
sudo apt upgrade nginx

Follow similar steps for updating your backend server or application, depending on what it is.

Conclusion

The ‘Incomplete headers (0 bytes) received from server’ error in NGINX can be a sign of various underlying problems, but it is frequently resolvable through methodical troubleshooting. By following the steps outlined in this guide, you should be able to diagnose and fix the issue, restoring the seamless operation of your web server and backend infrastructure.