简体   繁体   中英

Algolia search index fail

I have installed Algolia search plugin 1.7.0 in my WordPress site. I have also set it up and when I go into indexing the following shows up:

wp_remote_post() failed, indexing won't work. Checkout the logs for more details.
URL called: http://45.77.12.19/wp-admin/admin-post.php
Array
(
    [headers] => Requests_Utility_CaseInsensitiveDictionary Object
        (
            [data:protected] => Array
                (
                    [server] => nginx/1.12.0
                    [date] => Tue, 25 Apr 2017 02:23:09 GMT
                    [content-type] => text/html
                    [content-length] => 195
                    [www-authenticate] => Basic realm="Restricted"
                )
        )

401 Authorization Required

I have tried to add define( 'ALGOLIA_LOOPBACK_HTTP', true ) in the wp-config.php file and followed other steps explained:
https://community.algolia.com/wordpress/frequently-asked-questions.html

I am at a dead end and unsure of what to do now as the algolia indexing won't happen. How can I resolve this?

The Algolia plugin for WordPress needs to be able to access the admin interface over HTTP or HTTPS. This is the way it creates a loop to deal with the pending tasks.

According to your logs: 'Basic realm="Restricted"', your admin seems protected behind Basic Auth (htpasswd).

To make the queue work in your case, you should provide the plugin with the credentials.

Here is what you need to add to the functions.php file of your active theme.

<?php
// In your current active theme functions.php.
define( 'MY_USERNAME', 'test' );
define( 'MY_PASSWORD', 'test' );

function custom_loopback_request_args( array $request_args ) {
    $request_args['headers']['Authorization'] = 'Basic ' . base64_encode( MY_USERNAME . ':' . MY_PASSWORD );

    return $request_args;
}

add_filter( 'algolia_loopback_request_args', 'custom_loopback_request_args' );

Note that this will probably change in the upcoming weeks as we are working towards removing that logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM