• I am running a wordpress LEMP server with Ubuntu 20.04 Installed. I also have ngx_pagespeed module installed and running on Nginx. For the most part, things are working well, however when I use the wordpress health screen, I am getting the following error:

    The REST API encountered and unexpected result.
    
    The REST API is one way that WordPress and other applications communicate with the server. For example, the block editor screen relies on the REST API to display and save your posts and pages.
    
    When testing the REST API, an unexpected result was returned:
    
    REST API Endpoint: https://www.mcmo.is/wp-json/wp/v2/types/post?context=edit
    REST API Response: (403) Forbidden

    How can I go about debugging this, and what can I do to fix this error? What might be the cause of this?

    • This topic was modified 1 year, 5 months ago by danrancan.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi there,

    The 403 Forbidden error indicates that the server understands the request, but it refuses to authorize it. There can be a few reasons why this is happening, and here are steps you can take to debug and resolve this issue:

    Nginx Configuration: Ensure that your Nginx configuration is correctly set up to handle WordPress pretty permalinks and REST API requests. Make sure that your Nginx server block includes the necessary location directives. Example:

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

    Click here for more information.

    File Permissions: Check the permissions of your WordPress files and directories. Make sure that they are set correctly. Directories should typically be 755, and files should be 644.

    Click here for more information.

    CORS Headers: If your application is trying to access the REST API from a different domain or subdomain, you might need to set up CORS headers. You can do this by adding the following to your Nginx configuration:

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

    Please note that setting the Access-Control-Allow-Origin header to * will allow any site to make requests to your server, so it’s generally safer to replace * with the specific domain you want to allow.

    Click here for more information.

    WordPress REST API Routes: Ensure that no custom code or plugin is altering or blocking the default WordPress REST API routes.

    Click here for more information.

    Best regards,

    Christopher Amirian

    Forgot to mention, to make sure the settings are saved in Nginx you need to reload/restart the server:

    sudo nginx -s reload

    Or:

    sudo systemctl restart nginx

    These are all I could come up with.

    Best regards,

    Christopher Amirian

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Health Check: Rest API encountered an unexpected result (403) Forbidden’ is closed to new replies.