Diario

Nginx reverse proxy: WordPress «mixed content the page at ‘ url ‘ was loaded over https»

1 Mins read

En un entorno de reverse proxy con Nginx, cuando el Nginx frontal acepta solicitudes en 443 (HTTPS) e internamente realiza balanceo de carga round-robin en 80 (HTTP), a veces aparece un error de Mixed Content en Chrome.

Para resolver este problema, es efectivo agregar la siguiente configuración al principio de wp-config.php.

/** mixed content the page at ' url ' was loaded over https wordpress nginx */
/** 設定の場合、httpsでリダイレクトするように設定が必要! */
/** HTTP_X_FORWARDED_FOR の環境変数名はAWSなどお使いのサーバー環境により若干変更されている時があるので要確認すること */
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $_SERVER['HTTPS'] = 'on';
}

Si puede operar el archivo nginx.conf en el lado interno de 80 (HTTP), también puede aplicar la siguiente configuración.

Cualquiera de las dos opciones está bien.

location ~ \.php$ {
    include fastcgi_params;

    # mixed content the page at ' url ' was loaded over https wordpress nginx
    # プロキシ設定の場合、httpsでリダイレクトするように設定が必要!ここから
    fastcgi_param HTTPS on;
    fastcgi_param HTTP_X_FORWARDED_PROTO https;
    # ここまで

    fastcgi_intercept_errors on;
    fastcgi_pass php-fpm;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}