wordpress開啓https失敗問題

docker搭建的wordpress,nignx反向代理訪問,nginx加上ssl後,訪問WordPress,結果頁面裏js css仍是http請求。解決辦法以下php

  1. wp-includes\functions.php修改,找到require( ABSPATH . WPINC . ‘/option.php’ );在下方添加:
add_filter('script_loader_src', 'agnostic_script_loader_src', 20,2);
function agnostic_script_loader_src($src, $handle) {
	return preg_replace('/^(http|https):/', '', $src);
} 
add_filter('style_loader_src', 'agnostic_style_loader_src', 20,2);
function agnostic_style_loader_src($src, $handle) {
	return preg_replace('/^(http|https):/', '', $src);
}
  1. wp-config.php修改,找到@package WordPress在下方添加:
$_SERVER['HTTPS'] = 'on';
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
  1. 設置裏改成https
  2. 已發的文章中http修改https:(有些外鏈https不支持,因此不改)
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.xxx.com','https://www.xxx.com') WHERE post_content LIKE '%http://www.xxx.com%';
相關文章
相關標籤/搜索