Magento 2 shows Bad Gateway during installation using Nginx on Plesk Webserver
Recently we stumbled upon an issue, where a fresh Magento 2.4.x installation was not able to load the store frontend with a default Luma theme.
Instead of the store frontend, the Bad Gateway error appeared.
After we checked the logs we found the following error messages inside {{/var/www/vhosts/system/extendware.com/logs/}}
2022/04/08 12:38:39 [error] 5597#0: *1009761 upstream sent too big header while reading response header from upstream, client: 185.65.195.66, server: www.extendware.com, request: "GET /favicon.ico HTTP/2.0", upstream: "https://46.20.xxx.xxx:7081/favicon.ico", host: "www.extendware.com", referrer: "https://www.extendware.com/"
2022/04/08 12:38:41 [error] 5602#0: *1009799 upstream sent too big header while reading response header from upstream, client: 185.65.195.66, server: www.extendware.com, request: "GET / HTTP/2.0", upstream: "https://46.20.xxx.xxx:7081/", host: "www.extendware.com"
2022/04/08 12:38:42 [error] 5602#0: *1009799 upstream sent too big header while reading response header from upstream, client: 185.65.195.66, server: www.extendware.com, request: "GET /favicon.ico HTTP/2.0", upstream: "https://46.20.xxx.xxx:7081/favicon.ico", host: "www.extendware.com", referrer: "https://www.extendware.com/"
BASH
This lead us to the assumption, that the header data, provided by Magento via PHP simply where too big for the Nginx webserver to handle.
How we fixed the "upstream sent too big header" error
We adjusted the Nginx configuration file /etc/nginx/nginx.conf
by adding the following lines in the http secrtion of the config file:
http {
...
# Many lines of configuration before
...
# Fix for "upstream sent too big header while reading response header from upstream" for Magento 2
proxy_buffers 8 16k;
proxy_buffer_size 32k;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
...
# Many lines of configuration after here
...
}
BASH
We tested the Nginx config with:
nginx -t
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful
BASH
and finally restarted the Nginx to apply our patch:
systemctl restart nginx
BASH
After that the Magento store frontend was perfectly working.