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?

【簡単】ApacheでBasic認証

Posted at

はじめに

  • ApacheでBasic認証の設定する時のメモとして残します。

環境/前提

  • Apacheインストール済み
  • Apache:2.4.63
  • ubuntu:24.04.2

内容

認証ユーザーとパスワードを設定

  • -cにすると新規作成だけじゃなくて、上書きも可
sudo htpasswd -c /etc/apache2/.htpasswd ユーザー名

# 2回パスワード聞かれるので入力する
New password: パスワード
Re-type new password: パスワード

アクセス権を設定

  • .htpasswdファイルをapacheのみがアクセスできるように設定
  • 600:所有者 (ユーザー) に読み取りと書き込みの権限あり。グループと他のユーザーへは権限なしで設定
sudo chown apache:apache  /etc/apache2/.htpasswd
sudo chmod 600 /etc/apache2/.htpasswd

Apacheの設定

  • confファイルの設定
vim /etc/httpd/conf/httpd.conf

# 以下を入力
<Directory "/var/www/html">//ここはrootを記載
      AuthUserFile /etc/httpd/conf/.htpasswd
      AuthGroupFile /dev/null
      AuthName "Basic Auth"
      AuthType Basic
      Require valid-user
</Directory>

  • Apache再起動
sudo systemctl restart apache2
  • 該当ページへアクセスして確認する

まとめ

他にもBasic認証の方法がありますが、Apacheでする方法が簡単だったので、今回はこちらをメモとして残し。CloudflareのWorkersでもBasic認証できるみたいなので、今度はそれを試してみたい。

参考

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?