WordPress on App Service in Azure and upstream sent to big header error message

While moving a WordPress website to the WordPress on App Service recently, I ran into an error message being displayed in the Log steam within the Azure portal. That error message looked basically like this:

2024-04-11T00:10:40.437443394Z: [ERROR]  2024/04/11 00:10:40 [error] 968#968: *3123 upstream sent too big header while reading response header from upstream, client: 169.254.129.1, server: _, request: "POST /wp-admin/admin-ajax.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php-fpm.sock:", host: "{site}", referrer: https://{site}/

The fix for this is to edit the config file for the Nginx website and change some settings. Doing that is a little harder than normal, given that WebPress on App Service is a Platform as a Service (PaaS) offering, so you don’t have a whole lot of access to the machine running the web server. However, you do have a little more access than you’d expect. To fix this, we need to edit the nginx.conf file that the nginx web server is using. Doing that ends up being shocking and straightforward. The first step is to open the Azure portal and find the app service that is running the website, and select that app service.

Then scroll down to Development Tools and go into SSH (not Bash through the Advanced Tools). Once you have opened webssh, edit the file /etc/nginx/nginx.conf using your favorite text editor (I use vi because I’m old). Within this file, find the http section of the file, and at the bottom of that section, just above the }, add the following lines.

proxy_busy_buffers_size   512k;
proxy_buffers   4 512k;
proxy_buffer_size   256k;
fastcgi_buffers 16 32k;
fastcgi_buffer_size 64k;
fastcgi_busy_buffers_size 64k;
nginx.conf file after the above changes are added

When done, it should look something like this. (This is based on the default file with these changes added.) Now, this isn’t the end of the changes that you have to make. Where that file sits in the /etc directory doesn’t persist when the container restarts. This means that your changes will be overwritten when the container restarts or when a new container is spawned.

In order to overcome this, we need to copy the file to somewhere that is persisted. Everything under the /home folder is persisted if the container is restarted. We can stick the file there. This is done by copying the file to somewhere in the /home directory. This is done with cp /etc/nginx/nginx.conf /home/dev/nginx.conf (the /home/dev directory is a good place to store random config files.)

Now, we need to tell the container to use this file when it starts instead of the default config file. We do this by editing the /home/dev/startup.sh file. The file should already be there, but it should be empty. There are three lines that we need to put in this file (you can skip the first file if that line is already at the top of the file).

#!/bin/bash
cp /home/dev/nginx.conf /etc/nginx/nginx.conf
nginx -s reload

The first line tells Linux to use the bash system to run the file. The second line tells the system to copy the file to /etc/nginx. The third line tells nginx to restart using the config file. This will effectively tell the system to use your version of the configuration file rather than the default version.

If you need to make changes later for another reason, be sure to edit the version in /home/dev, not the active version. Then, restart the container(s) using the restart application button in the Azure portal.

Denny

Share

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.

Trust DCAC with your data

Your data systems may be treading water today, but are they prepared for the next phase of your business growth?