1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CloudFlareを導入したWebサイトにBasic認証を掛ける方法

Last updated at Posted at 2025-02-20

背景

Webサイトにクラウドフレアを導入した。

要望

コントロールパネルからではなく、Apacheの設定でBasic認証を導入したい

方法

# CloudFlareからの実際のクライアントIPを取得
SetEnvIf CF-Connecting-IP . CFIP=$0

# Basic認証の設定
AuthUserFile "/var/www/html/.htpasswd"
AuthName "Please enter your ID and password"
AuthType Basic
Require valid-user

# キャッシュ制御
<IfModule mod_headers.c>
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
</IfModule>

# オリジナルのIPアドレスをチェック
SetEnvIf CF-Connecting-IP "192\.10\.123\.[0-9]{1,3}" hoge

# アクセス制御
Order Allow,Deny

# 環境変数による制御
Allow from env=hoge

# 直接アクセスを許可
Allow from 192.01.123.0/24
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?