LoginSignup
1
1

More than 1 year has passed since last update.

【メモ】ベーシック認証(basic認証)を設定してIP制限をかける方法

Posted at

概要

Basic認証をかけつつIP制限をする機会があったのでメモ。
apacheです。

作業手順

  1. htpasswdファイルの作成
  2. httpd.confにBasic認証の設定を追加
  3. apacheをreload
  4. 動作確認

1. htpasswdファイルを作成

$ htpasswd -c /var/www/.htpasswd [username]

コマンドから作成しなくてもOK。

2. 設定ファイルにBasic認証の設定を追加

/etc/httpd/conf/httpd.conf

に以下を追加。

------------------------------------------
RemoteIPHeader X-Forwarded-For
<Location />
  AuthType Basic
  AuthName "Login"
  AuthUserFile /var/www/.htpasswd
  Require valid-user

  # 許可するIPを記入
  Require ip xxx.xxx.xxx.xxx
  Require ip xxx.xxx.xxx.xxx
</Location>
------------------------------------------

.htaccessファイルへの記載でもいいみたい。

3. apacheをreload

$ sudo systemctl reload httpd

4. 動作確認

許可したIPからのアクセスでBasic認証が求められないか&許可していないIPからのアクセスでBasic認証が求められるかを確認。

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