1. 程式人生 > >wordpress開啟https失敗問題

wordpress開啟https失敗問題

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

  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%';