0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

htaccessでstaging環境にのみIP制限をかける

Last updated at Posted at 2021-05-20

今回やりたいこと

下記の環境を用意しており

  • 本番環境
  • staging環境
  • local開発環境

staging環境にのみIP制限をかけたい

htaccessでやりたいこと

  • 特定のip、本番、localだと認証無しでアクセスできる
  • 上記じゃない場合、basic認証をとおす

htaccess記述内容

Order Deny,Allow
# Denyを評価したあとにAllow評価。今回は下記のDeny from allで一度全部拒否にしてその後でAllowを設定している。Satisfy Anyを最後につけることで一度DenyされていてもAllowに入っていれば通るようになっている
Deny from all
 
# 接続先ホスト名が www.example.com または localhost の場合の環境変数 NO_AUTH を定義
SetEnvIf HOST "^(www\.example\.com|localhost)$" NO_AUTH
# 環境変数(接続先ホスト名)による許可
Allow from env=NO_AUTH
 
# Basic認証      
AuthType Basic
AuthUserFile /home/xxxx/.htpasswds/passwd
AuthName "Login Password Required"
Require valid-user  
 
# IP アドレスがマッチする場合も許可する場合
# Allow from xxx.xxx.xxx.xxx
 
# Allow か Require いずれかの条件にマッチすれば許可
Satisfy Any

参考にした記事
https://www.tam-tam.co.jp/tipsnote/program/post7085.html

0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?