WordPress REST API Endpoint Not Accessible on Elastic Beanstalk with Nginx

0

I am encountering an issue with the WordPress REST API "The REST API encountered an unexpected result" on Elastic Beanstalk environment, which is using Nginx as the web server. Despite various attempts, including setting permalinks and reviewing Nginx configurations. I tried running "curl -X GET https://pinoyagri.com//wp-json/wp/v2/users" but I consistently receive a "404 Not Found" error when trying to access the REST API. I deactivated plugins. I have default theme Twenty Twenty-Three. Additionally, security group settings have been verified to allow traffic on ports 80 and 443. The error logs indicate that Nginx is unable to locate the necessary files or directories for the API. Any help is appreciated. Thank you.

profile picture
Vin
asked 8 months ago525 views
1 Answer
1

Hello.

Try running the command below.
If the permalink setting is "Basic", accessing "wp-json/wp/v2/" seems to result in 404 Not Found.
If the permalink setting is "Basic", please use the following URL to execute the Rest API.
https://stackoverflow.com/questions/34670533/wordpress-rest-api-wp-api-404-error-cannot-access-the-wordpress-rest-api

curl -X GET https://pinoyagri.com/index.php?rest_route=/wp/v2/users
profile picture
EXPERT
answered 8 months ago
  • Thank you providing me a good insight to resolve this issue. This request "curl -X GET https://pinoyagri.com/index.php?rest_route=/wp/v2/users" works. However when I run this "curl -X GET https://pinoyagri.com/wp-json/wp/v2/types/post?context=edit", it returned "404 Not Found". I just don't know the cause of this issue. I searched in the internet but most solutions are for Apache and my environment was set up in Nginx. This is the platform of my environment: PHP 8.2 running on 64bit Amazon Linux 2023/4.0.1. In my observation, there are endpoints that are not properly configured on my environment. Any help is appreciated.

  • You need to use the URL below as mentioned in my answer. Your WordPress permalink settings are probably set to "Basic". In that case, access the API from the URL below.

    curl -X GET https://pinoyagri.com/index.php?rest_route=/wp/v2/types/post?context=edit
    

    If I set the permalink setting to "Post Name", can I use it?

  • Yes and I'm using "Post Name" for my Permalinks. When I run "curl -X GET https://pinoyagri.com/index.php?rest_route=/wp/v2/types/post?context=edit", I got this output "{"code":"rest_no_route","message":"No route was found matching the URL and request method.","data":{"status":404}}". I really appreciate sharing me the post relevant to my issue. Meanwhile, do you think adding the following code to .ebextensions is good? "files: "/etc/nginx/conf.d/my_custom_config.conf": mode: "000644" owner: root group: root content: | location /wp-json { rewrite ^/wp-json(.*)$ /index.php?rest_route=$1 last; }"

  • The URL I shared seems to be successful with the following Nginx settings added. I see no problem with adding your settings. Try the following settings as well.

    location /wp-json/ { # Resolves WP Gutenberg 404 issue
      try_files $uri $uri/ /index.php;
    } 
    

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions