“Updating Failed” When Running WordPress Through linuxserver/letsencrypt Docker Container

In order to try and my docker setup, I trying to consolidate my docker containers and use docker images from a single provider. When I was getting started with docker, I found LinuxServer.io to be a great source for images. LinuxServer.io provides multiple architectures, common layers, easy user mappings, and much more.

For a while, I was running WordPress from the official docker image since that was the best one I could find at the time. I was never really happy with that container, since it didn’t allow me to easily run it under its own user account. When I was setting up the linuxserver/letsencrypt container for SSL and reverse proxy, I found out that it can host websites out of the box. I setup WordPress using this guide and instead of downloading the latest version of WordPress I just used the application files from that other docker container.

With this setup I did have one issue, every time I tried to save a draft or preview a post, I got this error:

Error: Updating failed

I also did some digging inspecting the source on the site and found this messages when WordPress was trying to POST:

POST https://slacktacular.com/wp-json/wp/v2/posts/59?_locale=user 404

With both of these errors, I was able to figure out that the problem occurred when using “pretty permalinks” in WordPress (which is enabled by default). If I switched to “Plain” permalinks things worked correctly, but I wanted to find the source of the problem. I came across this blog post that ended up getting to the right area:

https://nginxlibrary.com/wordpress-permalinks/

Things are slightly different with the linuxserver/letsencrypt container but both are based on nginx so it took a bit of playing around, but I managed to get it work. I had to do the following:

  1. Edit letsencrypt’s default file in a text editor:

    /opt/letsencrypt/nginx/site-confs/default

  2. Find the block that starts with “location /”

  3. If things are mostly default from the steps to setup word press, the fist line underneath that block should look something like this:

    try_files $uri $uri/ /index.html /index.php?$args =404;

  4. Replace this line with the following:

    try_files $uri $uri/ /index.html /index.php?$args;

  5. Restart your letsencrypt container

Once I removed that “=404” text, everything worked perfectly for me when I used the “pretty permalinks”. So far, I haven’t run across any issues with my other sites but I am not sure if/what that change would affect.