How do I get the Wordpress JSON-API to work on Nginx server?

My Nginx conf for wp-json API.

location / {
    # http://v2.wp-api.org/guide/problems/#query-parameters-are-ignored
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~ ^/wp-json/ {
    # if permalinks not enabled
    rewrite ^/wp-json/(.*?)$ /?rest_route=/$1 last;
}

My case was to deploy wordpress on a sub directory under the root dir of my website, here is the step to make it works

  1. The website root dir is /www/wwwroot/www.abc.com/public/ - access via www.abc.com
  2. The wordpress dir is /www/wwwroot/www.abc.com/public/blog/ - access via www.abc.com/blog/
  3. Download wordpress and unzip it to you web root dir, then rename it to blog
  4. chmod -R www:www blog - run this command in your web root dir.
  5. Add the following lines to your nginx config file.
location /blog/ {
  index index.php;
  try_files $uri $uri/ /blog/index.php?$args;
}

I found the solution to the problem. Make sure that permalinks are working properly before you assume (like I did) that it is an issue with the plugin.

I was able to correct permalinks for a wordpress site in a subdirectory on an nginx site. This article will help you if you face the same issue here