/wp-json rest api finally solved for nginx (wsl2/aws ebs tested)

Hey Roots Team,

tl;dr here is how to make nginx work with the rest api (/wp-json)

First off thank you for your incredible contribution to the WP/PHP community. I’ve been a Laravel developer for many years and more and more our clients are demanding WP as a CMS solution. I’ve tried to support you by buying all your addons and documents, anything that I can do.

We have some heavily trafficked sites we work on, and now I have a few sites now working as headless WP implementations, thanks to your efforts. One thing that has been a big problem for a while is getting the rest api to work under Bedrock (we run everything Sage too), under NGINX. (we run everything off AWS Elastic Beanstalks/locally docker windows WSL2 ubuntu). Countless searches, stack overflows, etc. It always worked with ?rest_route=/wp/v2/posts but we could never get it to work with the more “proper” /wp-json/wp/v2/posts, until now. This caused issues with paid plugins (like polylang-pro) to work well as they hardcode the latter.

So in the interest of documenting this for the future searches, and hopefully adding enough keywords to pick up for search, I’d like to offer the nginx configuration that makes wp-json work for WSL2/laradock/aws elastic beanstalk/nginx.

  location /wp-json/ { 
      try_files $uri $uri/ /index.php;
   } 

For the credit https://wordpress.stackexchange.com/a/379352/210335
I have a 1 reputation on that stack wp thing lol, so if this is useful for anyone in the future, please upvote it.
Don’t beat up on me too badly if this is a totally known thing, but wow this has really messed us up a long time. Sorry for the long post.

Cheers!
Bill

3 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.