目前我使用的wordpress的镜像是bitnami/wordpress-nginx,前端代理是traefik。昨天发现在评论部分,显示的ip是traefik的内网ip,172.10.0.2,这明显是不对的,大概看了下相关的代码什么的,实际上只要改一下wp-config.php就可以了。
if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$http_x_headers = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
$_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}
将以上代码,添加到wp-config.php的/* That's all, stop editing! Happy publishing. */
这一行上面即可。