Score:0

Nginx: *42 upstream sent too big header while reading response header from upstream - random behaviour

jm flag

I have an ec2 instance running nginx.

Here is my nginx config:


    server {
      listen       443 ssl;
      root         /var/www/angular/dist/testenpoint-website-angular;
      index        index.htm index.html;
      server_name  www.testenpoint.com;
      client_max_body_size 100m;
    
      location / {
      try_files $uri $uri/ /index.html;
    }
    
    location /applicationApis/ {
      root /var/www/html;
      try_files $uri $uri/ =404;
      include fastcgi_params;
      fastcgi_pass unix:/run/php-fpm/www.sock;
      fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }
    
    error_page 404 /404.html;
    location = /40x.html {
    }
    
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }
    
    
    ssl_certificate /etc/letsencrypt/live/testenpoint-all/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/testenpoint-all/privkey.pem; # managed by Certbot
    }
    
    server {
    if ($host = testenpoint.com) {
    return 301 https://$host$request_uri;
    } # managed by Certbot
    
    
    if ($host = www.testenpoint.com) {
    return 301 https://$host$request_uri;
    } # managed by Certbot
    
    
    listen      80;   #listen for all the HTTP requests
    server_name testenpoint.com www.testenpoint.com;
    return      301         https://www.testenpoint.com$request_uri;
    
    }
    
    server {
    if ($host = testenpoint.co.uk) {
    return 301 https://www.testenpoint.com$request_uri;
    } # managed by Certbot
    
    
    if ($host = www.testenpoint.co.uk) {
    return 301 https://www.testenpoint.com$request_uri;
    } # managed by Certbot
    
    
    listen      80;
    server_name testenpoint.co.uk *.testenpoint.co.uk;
    return      301         https://www.testenpoint.com$request_uri;
    
    
    }
    server {
    listen       443;
    server_name  testenpoint.co.uk *.testenpoint.co.uk;
    return       301         https://www.testenpoint.com$request_uri;
    }

I am calling this via my angular application like so:

https://www.testenpoint.com/applicationApis/getPdfReport.php

With the request is send auth header and in the body a few params. One param is called 'filterObject' this is a string object. When this is empty the request is fine. When I send stuff in there via my angular application I have a 404 response. Via postman, no issues. Via my test instance no issues.

This error appears in my nginx logs when this happens:


2023/01/03 19:28:50 [error] 24875#0: *42 upstream sent too big header while reading response header from upstream, client: xx.xx.xxx.xxx, server: www.testenpoint.com, request: "POST /applicationApis/getPdfReport.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "www.testenpoint.com", referrer: "http://localhost:4200/"

and

2023/01/03 19:28:50 [error] 24875#0: *42 open() "/var/www/angular/dist/my-website-angular/50x.html" failed (2: No such file or directory), client: xx.xx.xx.xx, server: www.testenpoint.com, request: "POST /applicationApis/getPdfReport.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock", host: "www.testenpoint.com", referrer: "http://localhost:4200/"

I am wondering if anyone can help here?

Also to note the the PHP code actually runs as I can see the logs etc all the way to completion. But all I get is a 404 even though my PHP code is showing no error. I believe it is an Nginx config issue and its only happening on this instance with this config and not my test instance with a slightly different config

Score:0
eg flag

If you have fastcgi enable you have to add in the location section:

fastcgi_buffers 16 32k;
fastcgi_buffer_size 64k;
fastcgi_busy_buffers_size 64k;

Source: https://www.cyberciti.biz/faq/nginx-upstream-sent-too-big-header-while-reading-response-header-from-upstream/

Score:0
cn flag

You need to edit your proxy buffer settings. This article will help: https://ma.ttias.be/nginx-proxy-upstream-sent-big-header-reading-response-header-upstream/

Then reload nginx.

Score:0
id flag

You need to identify where the request producing the original error was processed. 'Upstream' might be a lot of different things (proxy, fastcgi, uwsgi).

You need to tweak the proper upstream *_buffers and *_buffer_size to make the proper buffer(s) bigger.

You can set the following values and test if it works. If it doesn't work you can manually increase the value to 64k, 128k, 256k, and 512k. And then reload nginx.

*_buffers 16 32k;
*_buffer_size 64k;
*_busy_buffers_size 64k;
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.