====== 【Apache】.htaccess を使った Basic 認証 ====== ===== .htpasswd ファイルを生成 ===== # 既存のパスワードファイルがないか確認 ls -la /etc/httpd/conf/ # パスワードファイルを、新規作成/上書きする sudo htpasswd -c /etc/httpd/conf/.htpasswd USER_NAME # ファイルが既に存在する場合は「-c」を付けなければ「上書き」ではなく「追加」になる sudo htpasswd /etc/httpd/conf/.htpasswd USER_NAME # 確認 sudo cat /etc/httpd/conf/.htpasswd ===== .htaccess に Basic認証の記述を追加 ===== vi /var/www/html/.htaccess AuthType Basic AuthName "Member Only" AuthUserFile /etc/httpd/conf/.htpasswd Require user USER_NAME ===== Apache を再起動する ===== # コマンドは OS バージョンにより異なる sudo systemctl reload httpd