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

etrey picture etrey · May 21, 2015 · Viewed 8.2k times · Source

For some reason "out-of-the-box" the Wordpress JSON API does not work on Nginx. I have tried several redirect schemes in the nginx conf. The only thing I have gotten to work is ?json. However, this does not work for authentication and registration.

As an FYI, I am developing a cordova application and attempting to use the WP JSON API for WP backend.

Answer

northtree picture northtree · Jun 7, 2018

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;
}