1
1

More than 3 years have passed since last update.

Cloudflare SSL mode による HTTPS 化を確認する

Last updated at Posted at 2021-06-23

はじめに

Cloudflare では、以下の SSL mode を活用することで、Cloudflareーオリジン間の通信について、HTTPS を使うように制御できます。

Origin Server - SSL modes · Cloudflare SSL docs
image-20210623002113843

Cloudflareーオリジン間の通信が、実際に HTTPS で行われるかどうかを調査します。

確認方法

オリジン Web サーバーに Apache を使います。

Cloudflare からの HTTP リクエストヘッダを可視化する - Qiita

デフォルトでは Cloudflare によって、HTTP リクエストヘッダ X-Forwarded-ProtoCf-Visitor は同じ値に設定されます。

How does Cloudflare handle HTTP Request headers? – Cloudflare Help Center

今回は、オリジンサーバーで以下のように接続プロトコルごとに X-Forwarded-Proto を上書きするように設定を追加します。

/etc/httpd/conf/httpd.conf
RequestHeader set X-Forwarded-Proto "http"
/etc/httpd/conf.d/ssl.conf
<VirtualHost _default_:443>
RequestHeader set X-Forwarded-Proto "https"
</VirtualHost>

設定を反映するために、sudo systemctl restart httpd でサービスを再起動します。
その後に、以下のコマンドで確認できます。

curl -s http://khayama.ml | grep -e Cf-Visitor -e X-Forwarded-Proto
curl -s https://khayama.ml | grep -e Cf-Visitor -e X-Forwarded-Proto

Cloudflareーオリジン間の通信が HTTP の場合

X-Forwarded-Proto: http となります。
例えば、SSL mode を Flexible にした場合、クライアントーオリジン間を https で接続すると、Cloudflareーオリジン間の通信は http になります。

% curl -s https://khayama.ml | grep -e Cf-Visitor -e X-Forwarded-Proto
Cf-Visitor: {"scheme":"https"} <br />
X-Forwarded-Proto: http <br />

Cloudflareーオリジン間の通信が HTTPS の場合

X-Forwarded-Proto: https となります。
例えば、SSL mode を Strict (SSL-Only Origin Pull) にした場合、クライアントーオリジン間を http で接続すると、Cloudflareーオリジン間の通信は https になります。

% curl -s http://khayama.ml | grep -e Cf-Visitor -e X-Forwarded-Proto 
Cf-Visitor: {"scheme":"http"} <br />
X-Forwarded-Proto: https <br />

確認結果

以下のようになりました。

SSL mode Client --> Cloudflare Cloudflare --> Origin
Off HTTP HTTP
Off HTTPS --> HTTP (301 Redirect) -
Flexible HTTP HTTP
Flexible HTTPS HTTP
Full HTTP HTTP
Full HTTPS HTTPS
Full (Strict) HTTP HTTP
Full (Strict) HTTPS HTTPS
Strict (SSL-Only Origin Pull) HTTP HTTPS
Strict (SSL-Only Origin Pull) HTTPS HTTPS

完全に HTTPS 化するには

「Always Use HTTPS」の機能を使えば、クライアントーCloudflare間の通信に対して HTTP を HTTPS にリダイレクトできます。

How to make your site HTTPS-only
image.png

ただし、SSL mode = Off と「Always Use HTTPS」は併用できません。
image.png

「Always Use HTTPS」を組み合わせた場合の結果は、以下のようになります。

SSL mode Client --> Cloudflare Cloudflare --> Origin
Off HTTP HTTP
Off HTTPS --> HTTP (301 Redirect) -
Flexible HTTP --> HTTPS (301 Redirect) -
Flexible HTTPS HTTP
Full HTTP --> HTTPS (301 Redirect) -
Full HTTPS HTTPS
Full (Strict) HTTP --> HTTPS (301 Redirect) -
Full (Strict) HTTPS HTTPS
Strict (SSL-Only Origin Pull) HTTP --> HTTPS (301 Redirect) -
Strict (SSL-Only Origin Pull) HTTPS HTTPS
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1