脳汁portal

アメリカ在住(だった)新米エンジニアがその日学んだIT知識を書き綴るブログ

ubuntu16.04にapacheをinstallしてbasic認証をかける

1. install apache

apt-get install apache2

アクセスできることを確認
f:id:portaltan:20170321120846p:plain

2. basic auth

touch /etc/apache2/sites-available/auth-basic.conf
vi /etc/apache2/sites-available/auth-basic.conf
### 以下を入力して保存
<Directory /var/www/html>
    AuthType Basic
    AuthName "Basic Authentication"
    AuthUserFile /etc/apache2/.htpasswd
    require valid-user
</Directory>

htpasswd -c /etc/apache2/.htpasswd hoge
  New password: ******
  Re-type new password: ******
  Adding password for user hoge

cd /var/www/html
a2ensite auth-basic
  Enabling site auth-basic.
    To activate the new configuration, you need to run:
    service apache2 reload

sudo /etc/init.d/apache2 restart

もう一度アクセスしてbasic認証がかかっていることを確認
f:id:portaltan:20170321121815p:plain