WordPress REST API Misbehavior on Nginx

Working on this site with the new WP v5.8.2 I was hitting an error when using block editor.

I installed the ‘Classic Editor’ plugin so that I could keep working…

The data in the error looked like this…

Nc@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:72:66

@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:81:435

T@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:95:474

zj@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:230:157

Th@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:152:225

tj@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:152:154

Te@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:146:153

Te@[native code]

@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:61:69

unstable_runWithPriority@https://www.blandford.tech/wp-includes/js/dist/vendor/react.min.js?ver=16.13.1:25:261

Pg@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:61:16

ha@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:60:453

Ja@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:224:402

ch@https://www.blandford.tech/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.13.1:93:81

ch@[native code]

e@https://www.blandford.tech/wp-includes/js/dist/data.min.js?ver=a9e98fe3ad76884fe7909ba8348395b7:2:20892

t@https://www.blandford.tech/wp-includes/js/dist/data.min.js?ver=a9e98fe3ad76884fe7909ba8348395b7:2:20959

@https://www.blandford.tech/wp-includes/js/dist/data.min.js?ver=a9e98fe3ad76884fe7909ba8348395b7:2:15083

b@https://www.blandford.tech/wp-includes/js/dist/data.min.js?ver=a9e98fe3ad76884fe7909ba8348395b7:2:8589

@https://www.blandford.tech/wp-includes/js/dist/redux-routine.min.js?ver=fd5f93d1f8206c65d1891cf1f898211e:2:1354

some@[native code]

r@https://www.blandford.tech/wp-includes/js/dist/redux-routine.min.js?ver=fd5f93d1f8206c65d1891cf1f898211e:2:9237

@https://www.blandford.tech/wp-includes/js/dist/redux-routine.min.js?ver=fd5f93d1f8206c65d1891cf1f898211e:2:9187

promiseReactionJob@[native code]

Site Health (plugin) was giving me this…

Solution

I was able to get everything working by making sure that my Nginx site config contained the following:

location / {
try_files $uri $uri/ /index.php?$args;
}

You have to include the "?$args" part so non-default permalinks doesn't break when using query string

Lastly don’t forget to restart Nginx so that the changes are applied.

I hope this helps someone, since I wasted a couple hours getting to the bottom of this. 🙂