Khandaker Toihidul Islam
Front-end Developer
React Js | Javascript | HTML | CSS | Bootstrap | Wordpress | PHP | Mysql

upstream sent too big header while reading response header from upstream

Easy way to solve in nginx server
1. Suppose the configuration as

server {
        listen 80;
        listen [::]:80;

        root /var/www/html/cirk-l.com/public;
        index index.php index.html index.htm index.nginx-debian.html; 

        server_name example.com www.example.com  ;

        location / {
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri$args;
        }
		location ~ \.php$ {
		    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
		    include fastcgi_params;                
		    fastcgi_intercept_errors on;
		    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
		    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
		}
}

2. Now we need to add

fastcgi_buffers 16 16k; 
fastcgi_buffer_size 32k;

The final config should like

server {
        listen 80;
        listen [::]:80;

        root /var/www/html/cirk-l.com/public;
        index index.php index.html index.htm index.nginx-debian.html; 

        server_name example.com www.example.com  ;

        location / {
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri$args;
        }
		location ~ \.php$ {
		    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
		    include fastcgi_params;                
		    fastcgi_intercept_errors on;
		    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
		    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

                    fastcgi_buffers 16 16k; 
                    fastcgi_buffer_size 32k;
		}
}

3. Then need to run

ln -s /etc/nginx/sites-available/sub.example.com /etc/nginx/sites-enabled/sub.example.com

sudo nginx -t

sudo systemctl restart nginx

Happy programming

You may also like...