「Fedora 36」Apache 2.4.63で Basic認証を設定する方法

環境
OSバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cat /etc/redhat-release
Fedora release 36 (Thirty Six)
# cat /etc/redhat-release Fedora release 36 (Thirty Six)
# cat /etc/redhat-release
Fedora release 36 (Thirty Six)

httpdバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# httpd -V
Server version: Apache/2.4.53 (Fedora Linux)
# httpd -V Server version: Apache/2.4.53 (Fedora Linux)
# httpd -V
Server version: Apache/2.4.53 (Fedora Linux)

操作方法
1.Basic 認証ディレクトリを作成します
# mkdir /var/www/html/auth-basic

2.Basic 認証内容を設定します
# vi /etc/httpd/conf.d/auth_basic.conf
以下の内容を追記します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<Directory /var/www/html/auth-basic>
SSLRequireSSL
AuthType Basic
AuthName "Basic Authentication"
AuthUserFile /etc/httpd/conf/.htpasswd
Require valid-user
</Directory>
<Directory /var/www/html/auth-basic> SSLRequireSSL AuthType Basic AuthName "Basic Authentication" AuthUserFile /etc/httpd/conf/.htpasswd Require valid-user </Directory>
<Directory /var/www/html/auth-basic>
    SSLRequireSSL
    AuthType Basic
    AuthName "Basic Authentication"
    AuthUserFile /etc/httpd/conf/.htpasswd
    Require valid-user
</Directory>

3.Basic 認証ユーザーを登録します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# htpasswd -c /etc/httpd/conf/.htpasswd fedora
New password:    #パスワード入力
Re-type new password:   #パスワード確認
Adding password for user fedora
# htpasswd -c /etc/httpd/conf/.htpasswd fedora New password:    #パスワード入力 Re-type new password:   #パスワード確認 Adding password for user fedora
# htpasswd -c /etc/httpd/conf/.htpasswd fedora
New password:    #パスワード入力
Re-type new password:   #パスワード確認
Adding password for user fedora

4.httpdを再起動します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl restart httpd
# systemctl restart httpd
# systemctl restart httpd

5.テストページを作成します
# vi /var/www/html/auth-basic/index.html

以下の内容を追記します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<html>
<body>
Basic Authentication Test Page
</body>
</html>
<html> <body> Basic Authentication Test Page </body> </html>
<html>
<body>
Basic Authentication Test Page 
</body>
</html>

 

 

Fedora 36

Posted by arkgame