総数:11 今日:1 昨日:0
apache2.4.18にダイジェスト認証を設定する
~$ apache2 -version Server version: Apache/2.4.29 (Ubuntu) Server built: 2018-10-03T14:41:08
~$ sudo mkdir -p /var/www/html/auth_required_dir/
~$ ls -la /etc/apache2/sites-enabled/ 合計 8 drwxr-xr-x 2 root root 4096 10月 8 21:57 . drwxr-xr-x 9 root root 4096 10月 8 22:02 .. lrwxrwxrwx 1 root root 35 10月 8 21:57 000-default.conf -> ../sites-available/000-default.conf
~$ ls -la /etc/apache2/sites-available/ 合計 20 drwxr-xr-x 2 root root 4096 1月 28 15:43 . drwxr-xr-x 9 root root 4096 1月 28 15:25 .. -rw-r--r-- 1 root root 1599 1月 28 15:43 000-default.conf -rw-r--r-- 1 root root 6338 4月 6 2016 default-ssl.conf
~$ sudo gvim -f /etc/apache2/sites-available/000-default.conf
~$ cat /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
#ここから追記開始
<Directory "/var/www/html/auth_required_dir">
AuthType Digest
AuthName "realm_auth_required_dir"
AuthDigestDomain /auth_required_dir/
AuthUserFile /etc/apache2/.htdigest
Require user username
</Directory>
#ここまで追記おわり
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
~$ sudo htdigest -c /etc/apache2/.htdigest realm_auth_required_dir username
~$ sudo a2enmod auth_digest
~$ sudo service apache2 restart
~$ wget http://hostname/auth_required_dir/file_to_be_downloaded --2018-01-28 18:30:50-- http://hostname/auth_required_dir/file_to_be_downloaded hostname:80 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... 401 Unauthorized Username/Password による認証に失敗しました。
~$ wget --http-user=username --http-password=password http://hostname/auth_required_dir/file_to_be_downloaded.tar.gz --2018-01-28 18:30:13-- http://hostname/auth_required_dir/file_to_be_downloaded.tar.gz hostname:80 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... 401 Unauthorized 選択された認証形式: Digest realm="realm_auth_required_dir", nonce="省略", algorithm=MD5, domain="/auth_required_dir/", qop="auth" hostname:80 への接続を再利用します。 HTTP による接続要求を送信しました、応答を待っています... 200 OK 長さ: 34845682 (33M) [application/x-gzip] `file_to_be_downloaded.tar.gz' に保存中 file_to_be_downloaded.tar.gz 100%[==========================================>] 33.23M --.-KB/s in 0.07s 2018-01-28 18:30:13 (494 MB/s) - `file_to_be_downloaded.tar.gz' へ保存完了 [34845682/34845682]