How to fix 502 Bad Gateway error ( upstream sent too big header while reading response header from upstream ) after clean installation of magento 2.4.x in nginx + apache config or nging + php-fpm?

Just increase your proxy buffer in nginx config using:

apache ( php7.4 ) + nginx ( usually in location @fallback { section ) :

proxy_buffer_size 16k;
proxy_busy_buffers_size 16k;

nginx + php-fpm:

fastcgi_buffers 16 16k; 
fastcgi_buffer_size 32k;