wp-json/ return 404, but wp-json/wp/v2/ works fine on my nginx server

When I access my WordPress site as www.example.com/wp-json/ I got this 404 error.

`{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}`

But the REST api return the correct json object if I use the url of www.example.com/wp-json/wp/v2/.

My permalink is setup as /%year%/%monthnum%/%postname%/, and here is part of my nginx configuration settings:

server {

    root /var/www/html;
    index index.php index.html index.htm;

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

    # other location directives related to php, cache, etc.

}

I searched on Internet and most of the problems seems to be caused by incorrect permalink setting and .htaccess (Apache), but seldom mentioned about the case related to nginx. Any idea what cause this and how to solve it?

Update

If I run curl -i www.example.com/wp-json, this is what I get:

HTTP/1.1 404 Not Found
Server: nginx
Date: Sun, 29 Jan 2017 11:58:21 GMT
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Robots-Tag: noindex
Link: <https://example.com/wp-json/>; rel="https://api.w.org/"
X-Content-Type-Options: nosniff
Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
Access-Control-Allow-Headers: Authorization, Content-Type

{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}

Latest Update (7 Mar 2017)

With the release of WordPress 4.7.3, this bug has been fixed. The workaround unset ($_SERVER['PATH_INFO']); no longer needed.

Solutions Collecting From Web of "wp-json/ return 404, but wp-json/wp/v2/ works fine on my nginx server"

Could this be about https://core.trac.wordpress.org/ticket/39432

Symptoms look very similar and at the time of writing hasn’t been released as 4.7.3. Applying the patch manually fixed the issue on my nginx setup.

Just ran into the same issue on an nginx only (no Apache) WordPress blank install 4.7.2 site.

The base /wp-json/ & index.php?rest_route=/ URLs showing rest_no_route 404, but all the /wp-json/wp/v2/ working just fine.

The issue turned out to be related to the PATH_INFO variable passed by nginx that WordPress core attempts to build the URL off of incorrectly, if it’s set to anything, even an empty string.

Needs more investigating, but I was able to fix by adding a condition on those specific pages via REQUEST_URI by doing this for them:

unset($_SERVER['PATH_INFO']);

For me, updating the permalinks to something special than the first option did the job.