[WordPress] Nginx Mobile Theme+CloudFrontでモバイル判別を可能にする方法

CloudFront配下のNginxベースのwordpressでモバイル判定しテーマを変更するNginx Mobile Themeとの連携方法は、CloudFrontの設定で「CloudFront-Is-Mobile-Viewer」を有効にし、Nginx設定に以下の設定を追加する。

CloudFrontからのUser AgentはAppleなどのメジャーな文字列ではなく、$http_cloudfront_is_mobile_viewerに格納されてくるので、$http_cloudfront_is_mobile_viewerで判定する。

/etc/nginx/conf.d/default.conf もしくは xxxx.confの

set $mobile '';
include /etc/nginx/mobile-detect;

set $mobile '';
include /etc/nginx/mobile-detect;
if ( $http_cloudfront_is_mobile_viewer = 'true' ) {
    set $mobile "@smartphone";
}

に変更する

ちなみにCloudFront配下のNginxベースのwordpressを配置し、Nginx Mobile Themeでモバイル判定させる環境を作成すると、なぜかMobile Templete中のウィジェットが一部動作しなかった。

WorkAroundとして、ウィジェットに書きたかったそれぞれのモジュールを直接それぞれのphpに書くことで回避できた。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です