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
- The website root dir is
/www/wwwroot/www.abc.com/public/
- access viawww.abc.com
- The wordpress dir is
/www/wwwroot/www.abc.com/public/blog/
- access viawww.abc.com/blog/
- Download wordpress and unzip it to you web root dir, then rename it to
blog
chmod -R www:www blog
- run this command in your web root dir.- 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