HostOnNet Blog

Nginx upstream sent too big header while reading response header from upstream

Looking for Linux Server Admin or WordPress Expert? We can help.

Nginx Bad Gateway

On a wordpress blog hosted under Nginx and php-fpm, when adding new post, get 502 internal error.

2017/11/01 08:40:16 [error] 30159#30159: *74037 upstream sent too big header while reading response header from upstream, client: 35.195.113.110, server: www.hostonnet.com, request: "POST /wp-admin/post.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "hostonnet.com", referrer: "https://hostonnet.com/wp-admin/post-new.php?wp-post-new-reload=true"

This is fixed by editing nginx config for the web site by adding

fastcgi_buffers 16 16k; 
fastcgi_buffer_size 32k;

Here is the updated nginx config

server {
        listen 443;
        server_name www.blog.hostonnet.com blog.hostonnet.com;
        root /home/hostonnet/public_html/;
        index index.php;
 
        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }
 
        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }
 
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
 
        location ~ \.php$ {
            fastcgi_buffers 16 16k; 
            fastcgi_buffer_size 32k;
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
 
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
 
        ssl on;
        ssl_certificate /etc/ssl/blog.hostonnet.com.crt;
        ssl_certificate_key /etc/ssl/blog.hostonnet.com.key;
 
}
 
server {
    listen 80;
    server_name  www.blog.hostonnet.com blog.hostonnet.com;
    return       301 https://blog.hostonnet.com$request_uri;
}

Posted in Nginx

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.