wordpress開啟https失敗問題
阿新 • • 發佈:2018-11-30
docker搭建的wordpress,nignx反向代理訪問,nginx加上ssl後,訪問WordPress,結果頁面裡js css還是http請求。解決辦法如下
- 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); }
- wp-config.php修改,找到@package WordPress在下方新增:
$_SERVER['HTTPS'] = 'on';
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
- 設定裡改為https
- 已發的文章中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%';