Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 345
etrey Avatar asked May 21 '15 16:05

etrey


People also ask

Does Nginx work with WordPress?

Both Apache and NGINX work well with WordPress hosting.

Does nginx have an API?

The NGINX Controller API is a REST API that allows you to programmatically manage your NGINX Plus data planes. NGINX Controller follows an “API-first” approach, which means that all NGINX Controller functionality is exclusively exposed through declarative and resource-oriented APIs.


1 Answers

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;
}
like image 100
northtree Avatar answered Sep 22 '22 06:09

northtree