tkuchikiの日記

新ブログ https://blog.tkuchiki.net

Apache と Nginx でBasic認証をかける&特定IPのみ許可の設定

設定する度にググっているのでメモ。

Apache

# Basic auth
AuthUserFile /var/www/html/example.com/.htpasswd
AuthGroupFile /dev/null
AuthName "basic authentication"
AuthType Basic
require valid-user

Satisfy any

Order deny,allow
Deny from all
Allow from xxx.xxx.xxx.xxx

Satisfy any は、いずれかの条件を満たす場合、
Satisfy all にすれば、すべての条件を満たす場合にできる。
Directory セクション内に記述可能(core - Apache HTTP Server)。

Nginx

auth_basic "basic authentication";
auth_basic_user_file /var/www/html/exmaple.com/.htpasswd;

satisfy any;
allow xxx.xxx.xxx.xxx;
deny all;

location、server、http、limit_except ブロック 内に記述可能(HttpAuthBasicModule)