Skip to content

Instantly share code, notes, and snippets.

@eezis
Created November 6, 2022 17:27
Show Gist options
  • Save eezis/4e53568b7820fa1ce1c824f0e1b7ced9 to your computer and use it in GitHub Desktop.
Save eezis/4e53568b7820fa1ce1c824f0e1b7ced9 to your computer and use it in GitHub Desktop.
Django EC2 ELB Nginx PageSpeed upstream sent more data than specified in "Content-Length" header

While upgrading EC2 servers behind an AWS Elastic Load Balancer (ELB) I noticed that the nginx error log was reporting that my health-check was getting molested. Here is the simple curl test showing the 200 result. The error message, then the solution follow.

$ curl -I localhost/ELB-health-check

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 06 Nov 2022 16:59:46 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 105
Connection: keep-alive
Vary: Accept-Encoding
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Cross-Origin-Opener-Policy: same-origin

This is the [warn] error message I was observing in the error.log

2022/11/06 16:58:31 [warn] 7510#7510: *5 upstream sent more data than specified in "Content-Length" header while reading upstream, client: 127.0.0.1, server: example.com, request: "HEAD /ELB-health-check HTTP/1.1", upstream: "http://127.0.0.1:8000/ELB-health-check", host: "localhost"
2022/11/06 16:58:32 [warn] 7510#7510: *7 upstream sent more data than specified in "Content-Length" header while reading upstream, client: 127.0.0.1, server: example.com, request: "HEAD /ELB-health-check HTTP/1.1", upstream: "http://127.0.0.1:8000/ELB-health-check", host: "localhost"
2022/11/06 16:58:33 [warn] 7510#7510: *9 upstream sent more data than specified in "Content-Length" header while reading upstream, client: 127.0.0.1, server: example.com, request: "HEAD /ELB-health-check HTTP/1.1", upstream: "http://127.0.0.1:8000/ELB-health-check", host: "localhost"


Problem Context: ELB was passing the health-check and allowing me to add this server to the load balancing roation, but it was definitely deprioritizing it and it wasn't getting much traffic. All the other pages that I was serving were being accessed and delivered without error or issue. After some trial and error exploration I discovered that straight nginx handled the test without creating an error and that it was only when pagespeed was in use that the error occured. The problem was present for gunicorn and uwsgi.


Solution: Disallow the ELB url from getting "pagespeeded"

    ## load pagespeed configuration
    include /etc/nginx/sites-available/pagespeed.your-site.conf;
    pagespeed Disallow "*/ELB-health-check";

Hope this hopes someone in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment