W3TC?
https://wordpress.org/plugins/w3-total-cache/
W3TC というプラグインを使っていてですね。
簡単に AmazonS3 や CloudFront に同期してくれるので非常に助かったのですが。
事件はおきた
セキュリティを考慮して Web サーバと Admin サーバを分けたのですね。
それに伴って、Webサーバと Adminサーバのドメインも変えました。
そのために、「WordPress アドレス (URL)」 と 「サイトアドレス (URL)」 をそれぞれ
「http://admin.wordpress/ 」と「 http://web.wordpress/ 」に変更したんですよ。
そしたら今まで正常に動いてた CloudFront へのアクセスが死亡しました。
どうなったかと言うと、正しくは
http://xxxx.cloudfront.net/wp-content/...
となるはずが
http://xxxx.cloudfront.net/http://admin.wordpress/wp-content/...
なんだこれ。URL生成に失敗してんじゃんと。
原因は?
散々悩んだあげく、以下の情報を発見。
http://wpml.org/ja/forums/topic/wpml-not-working-with-w3-total-cache/
・・・(前略)・・・
I'm not sure what the long term fix is, but I ended up hacking my Cdn.php file ob_callback function with the following:
$domain_url_regexp = str_replace("xxxxx\\.cn", "xxxxx\\.com", $domain_url_regexp);
at line 236
・・・(後略)・・・
どうやら callback で呼ばれる ob_callback
というメソッドで正しく置換ができてない模様。
http://web.wordpress/wp-content/...
↓ // '(https?:)?//(www\.)?web\.wordpress' の正規表現で host 削除
/wp-content/...
↓ // CloudFront のホスト付与
http://xxx.cloudfront.net/wp-content/...
となるはずが、管理サーバのドメイン(siteurl)を変えたせいで
http://admin.wordpress/wp-content/...
↓ // '(https?:)?//(www\.)?web\.wordpress' の正規表現で host 削除→失敗!
http://admin.wordpress/wp-content/...
↓ // CloudFront のホスト付与
http://xxx.cloudfront.net/http://admin.wordpress/wp-content/...
になってるようで。
解決?
以下のコードを追加。動作検証ちゃんとはしてないのでちゃんと動くか怪しい。
if(strcmp($site_domain_url_regexp, $domain_url_regexp) !== 0 ) {
$domain_url_regexp = $site_domain_url_regexp;
}
ひとまず見れるようにはなった。
時間がなくて調べきれてないので、誰かいい解決方法教えて下さい。
追記(2014/08/20)
いつのまにか、CDNを設定を有効にしていたのにも係わらずCDNが無効になっていた。
つまり、CloudFront のパスを向いてくれているはずが、管理画面のURLになっていた・・・。
○正しくは
http://xxx.cloudfront.net/wp-content/...
↓↓↓
×それがこう
http://admin.wordpress/wp-content/...
原因
(抜粋)
Check to make sure your Unsuccessful file transfer queue is not full of errors. If this queue is full of errors, it may prevent some files from using the cdn. Use the delete queue option when viewing to empty the queue.
つまるところ、CDNへの自動アップロードを管理しているテーブル(キューとして使ってる)がエラーで埋まってると、無効になると。
実際調べてみた。
mysql> SELECT count(*) FROM wp_w3tc_cdn_queue;
=> 1209
mysql> SELECT * FROM wp_w3tc_cdn_queue;
+----+------------+-------------+---------+---------------------------------+------+
| id | local_path | remote_path | command | last_error | date |
+----+------------+-------------+---------+---------------------------------+------+
| 11 | localpath1 | remotepath1 | 1 | Unable to put object (S3::putObject(): [7] couldn't connect to host). | 2014-08-19 08:51:48 |
| 12 | localpath2 | remotepath2 | 1 | Unable to put object (S3::putObject(): [7] couldn't connect to host). | 2014-08-19 08:51:48 |
| 13 | localpath3 | remotepath3 | 1 | Unable to put object (S3::putObject(): [7] couldn't connect to host). | 2014-08-19 08:51:48 |
| 14 | localpath4 | remotepath4 | 1 | Unable to put object (S3::putObject(): [7] couldn't connect to host). | 2014-08-19 08:51:48 |
| 15 | localpath5 | remotepath5 | 1 | Unable to put object (S3::putObject(): [7] couldn't connect to host). | 2014-08-19 08:51:48 |
...
Unable to put object (S3::putObject(): [7] couldn't connect to host).
やら Source file not found
やら、エラーのオンパレードでございました本当にありがとうございました\(^o^)/
という訳で、中身を空にしたら無事解決。
mysql> TRUNCATE TABLE wp_w3tc_cdn_queue;
Query OK, 0 rows affected (0.27 sec)
mysql> SELECT * FROM wp_w3tc_cdn_queue;
Empty set (0.18 sec)
自動アップロードは諦めるか・・・。