woocommerce 不会在两个 natted 服务器之间触发 webhook

woocommerce doesn't fire webhooks between two natted servers

使用云解决方案,我的服务器位于防火墙后面并使用私有 class IP 地址进行 NAT。

我创建了一个 webhook,它会在每次将商品添加到购物车时调用 URL 网站:

但 webhook 从未被触发

阅读我找到的所有文档(几页)后,我发现 wordpress 允许仅针对自身和 public IP 发出 http 请求,使用 wp_http_validate_url,他的行为可以被过滤器覆盖:http_request_host_is_external

functions.php 中,我添加了覆盖挂钩:

add_filter( 'http_request_host_is_external','allowed_http_request_hosts_local', 10, 2 );

以及使用我的网络服务器地址实现的功能:

function allowed_http_request_hosts_local( $is_external, $host ) {
    $hosts_white_list=[];
    $hosts_white_list[]="www.example.com";
    if ( ! $is_external && in_array($host,$hosts_white_list) )
        $is_external = true;
       return $is_external;
}

Wordpress 在 cron-table 中安排 webhooks,因此当 WP 在 shop.example.com/wp_cron.php[ 调用自己时它们会触发=30=] 许多防火墙不允许调用防火墙后面的 public IP,所以我结束配置将商店的私有地址添加到他的 /etc/hosts:

192.168.1.10 shop.example.com

一切正常!