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

More than 1 year has passed since last update.

同じサーバー内の複数サイトにBasic認証をかけた

Posted at

動作環境

AlmaLinux 8.5
php 7.4.27

サーバー構造

サイトA
/var/www/html/example_a.com
サイトB
/var/www/html/example_b.com

この2つのサイトに、別のID、パスワードを持つBasic認証をかける

DocumentRootより上層にパスワードファイル用ディレクトリを作成

mkdir /var/www/htmml/keybox

サイトAの管理画面にBasic認証をかける

.htaccess作成

DocumentRoot直下に作成

vim /var/www/html/example_a.com/.htaccess
# 管理画面へのBasic認証
#
AuthType Basic
AuthName "Please enter username and password"
AuthUserFile /var/www/html/keybox/examplea.htpasswd
AuthGroupFile /dev/null
require valid-user
SetEnvIf Request_URI "^/[管理画面パス]" admin_path  # ^/adminは, 管理画面URLに応じて変更してください
<RequireAll>
    Require all granted
    Require not env admin_path
</RequireAll>

暗号化パスワード作成

https://www.luft.co.jp/cgi/htpasswd.php

.htpasswd作成

vim /var/www/html/keybox/examplea.htpasswd
[ユーザーネーム]:[暗号化パスワード]

フロントで確認

https://example_a.com/[管理画面パス]

サイトBのトップページにBasic認証をかける

.htaccess作成

DocumentRoot直下に作成

vim /var/www/html/example_b.com/.htaccess
# 管理画面へのBasic認証
#
AuthType Basic
AuthName "Please enter username and password"
AuthUserFile /var/www/html/keybox/exampleb.htpasswd
AuthGroupFile /dev/null
require valid-user
SetEnvIf Request_URI "^/" admin_path  # ^/adminは, トップページURLに応じて変更してください
<RequireAll>
    Require all granted
    Require not env admin_path
</RequireAll>

暗号化パスワード作成

https://www.luft.co.jp/cgi/htpasswd.php

.htpasswd作成

vim /var/www/html/keybox/exampleb.htpasswd
[ユーザーネーム]:[暗号化パスワード]

フロントで確認

https://example_b.com/


参考記事

https://qiita.com/chihiro-adachi/items/64707ca3250eee3f43c8
https://qiita.com/yuwaita/items/e406c645ae8d0cc3c3fa#:~:text=%E3%82%A2%E3%83%83%E3%83%97%E3%81%99%E3%82%8B%E5%A0%B4%E6%89%80-,.,%E4%B8%8A%E3%81%AB%E8%A8%AD%E7%BD%AE%E3%81%99%E3%82%8B%E3%81%93%E3%81%A8%E3%80%82

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