Can’t startup Cornerstone after activating SSL in Wordpress theme X

Can’t startup Cornerstone after activating SSL in Wordpress theme X

Date
May 26, 2018
Tags
FE Development
notion image
使用  cornerstone 的朋友可能在啟動 SSL 後會碰到以下的問題。 The preview could not load due to http/https mismatch. Please check that HTTPS is properly configured on your site。
這是因為在 wordpress 裡很多已有的連結在數據庫裡都是用 http 開頭,解決的辦法只能是到 database 裡把所有是 http://[domain name] 的改為是 https://[domain name]
最簡單的做法先試用 SSL Secure Content Mixer, 如果用後還不行的話,可以使用以下的方法。
notion image
更改 wp_sitemeta 裡的 URL
mysql> select * from wp_sitemeta where meta_key = 'siteurl'; +---------+---------+----------+------------------------+ | meta_id | site_id | meta_key | meta_value | +---------+---------+----------+------------------------+ | 14 | 1 | siteurl | http://jackvisuals.com | +---------+---------+----------+------------------------+ 1 row in set (0.00 sec) mysql> update wp_sitemeta set meta_value = 'https://jackvisuals.com' where meta_key = 'siteurl'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
如果你不是用 wordpress multisite 的話,這個 site option 裡的 URL 是可以在 admin page 裡修改的。如不是的話,要在 database 裡更改一下
mysql> update wp_options set option_value = 'https://jackvisuals.com' where option_name = 'home'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update wp_options set option_value = 'https://jackvisuals.com' where option_name = 'siteurl'; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0
在 database 裡先看看 wp_posts 有那些 columns
mysql> show columns in wp_posts; +-----------------------+---------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+---------------------+------+-----+---------------------+----------------+ | ID | bigint(20) unsigned | NO | PRI | NULL | auto_increment | | post_author | bigint(20) unsigned | NO | MUL | 0 | | | post_date | datetime | NO | | 0000-00-00 00:00:00 | | | post_date_gmt | datetime | NO | | 0000-00-00 00:00:00 | | | post_content | longtext | NO | | NULL | | | post_title | text | NO | | NULL | | | post_excerpt | text | NO | | NULL | | | post_status | varchar(20) | NO | | publish | | | comment_status | varchar(20) | NO | | open | | | ping_status | varchar(20) | NO | | open | | | post_password | varchar(255) | NO | | | | | post_name | varchar(200) | NO | MUL | | | | to_ping | text | NO | | NULL | | | pinged | text | NO | | NULL | | | post_modified | datetime | NO | | 0000-00-00 00:00:00 | | | post_modified_gmt | datetime | NO | | 0000-00-00 00:00:00 | | | post_content_filtered | longtext | NO | | NULL | | | post_parent | bigint(20) unsigned | NO | MUL | 0 | | | guid | varchar(255) | NO | | | | | menu_order | int(11) | NO | | 0 | | | post_type | varchar(20) | NO | MUL | post | | | post_mime_type | varchar(100) | NO | | | | | comment_count | bigint(20) | NO | | 0 | | +-----------------------+---------------------+------+-----+---------------------+----------------+ 23 rows in set (0.00 sec)
從上面看到,應該所有內容都是在 post_content 裡。那很簡單,只需要 replace 這裡的內容就是了。運行以下的 SQL
mysql> update wp_posts set post_content = replace(post_content, 'http://jackvisuals.com', 'https://jackvisuals.com') where post_content like '%http://jackvisuals.com%'; Query OK, 2684 rows affected (3.42 sec) Rows matched: 2684 Changed: 2684 Warnings: 0
到這裡再啟動 Cornerstone,應該就好了。
註: 如果有使用 Cloudflare 的話, 另一可能性的原因是在 Cloudflare 裡的 Crypto app 預設使用了 Flexible。這情況下, Cloudflare 只會 encrypt 它與用戶 Browser 之間的連線,不會 encrypt 它與 Origin server 的連線。所以也可把設定改成 Full 。