Roots Discourse

/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
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.



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