WordPress wp-json API failed after customising permalink (nginx misconfiguration)

Over the years, I have been hosting multiple wordpress sites and developed multiple websites using the platform. I’ve migrated sites across multiple hosts and from fewer versions older to the latest version.

Recently, I’ve migrated my site to another server, which clean setup. However, my setup of google site kit kept throwing me errors and I can’t connect directly from wordpress app.

I’ve played around with it for a little while and realised that it has something to do with permalink. If I select the default format, i.e. ?p=x format, it works fine. It stays to break when I choose custom permalink.

Then I continue to hunt around for the root cause and realised that I’ve missed a configuration on my web server config (in this case is nginx).

To fix this, I have to edit my site config (in this example, it’s default site. change it to your site config if you have a different name for it).

Simply replace the following line try_files $uri $uri/ =404; with try_files $uri $uri/ /index.php?$args; and restart your nginx service with

systemctl restart nginx.service

Then try to access your wp-json API again or try to load your google site kit again, and it should work fine.

About: author