Coolify + N8N + WordPress Error: “Couldn’t connect with these settings (Unauthorized)”

Coolify + N8N + WordPress Error: “Couldn’t connect with these settings (Unauthorized)”

Sounds simple, but can lead to madness on secure servers: The connection of N8N with a WordPress installation.

First of all, it is advisable to resolve the IP address for the name correctly directly in the Docker container, e.g. to avoid problems with the CDN or an upstream firewall.

To do this, go to the configuration in Coolify and select “Edit Compose File” and then enter the corresponding extra hosts:

extra_hosts:
      - "example.com:1.1.1.1"
      - "www.example.com:1.1.1.1"

Then save and go to “Pull Latest Images & Restart” under “Advanced” to apply the changes.

When using Plesk on the target server with activated WAF, an exception rule via the “Custom Directives” of the WAF is recommended, example:

SecRule REMOTE_ADDR "@ipMatch 1.1.1.1" "id:4,phase:1,pass,nolog,ctl:ruleEngine=Off"

In the respective WordPress installation there will certainly also be Wordfence, here too it is recommended to whitelist the IP of the N8N server and also to deactivate “Prevent discovery of usernames through ‘/?author=N’ scans, the oEmbed API, the WordPress REST API, and WordPress XML Sitemaps”.

The connection should then work:

But of course this is still not the end of the story, the next error message awaits you immediately:

“Authorization failed – please check your credentials
401 Sorry, you are not allowed to create posts as this user.”

The “Disable WordPress application passwords” option must also be deactivated in Wordfence.

In functions.php we can allow all administrators to post new posts via the API:

add_filter('rest_post_can_create', function($can_create, $post_type, $request) {
    // force allow for admins
    if(current_user_can('administrator')) {
        return true;
    }
    return $can_create;
}, 10, 3);

Leave a Reply

Your email address will not be published. Required fields are marked *