りんちゃんの日記

日常を書き留めていきます。

apache ベーシック認証

1. ベーシック認証

 1.1. httpd.confを編集する(赤文字の箇所を修正)
    # cd /etc/httpd/conf
    # vi httpd.conf

 AllowOverride None → AllowOverride ALL に変更(339行目付近)

 ------------------------------------------------------------------------------------------------------------

  <Directory "/var/www/html">
  #
  # Possible values for the Options directive are "None", "All",
  # or any combination of:
  # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
  #
  # Note that "MultiViews" must be named *explicitly* --- "Options All"
  # doesn't give it to you.
  #
  # The Options directive is both complicated and important. Please see
  # http://httpd.apache.org/docs/2.4/mod/core.html#options
  # for more information.
  #
  Options Indexes FollowSymLinks

  #
  # AllowOverride controls what directives may be placed in .htaccess files.
  # It can be "All", "None", or any combination of the keywords:
  # Options FileInfo AuthConfig Limit
  #
  # AllowOverride None
  AllowOverride ALL

  #
  # Controls who can get stuff from this server.
  #
  Require all granted
</Directory>

------------------------------------------------------------------------------------------------------------

 1.2. DocumentRootの場所確認

     # cd /etc/httpd/conf
  # cat httpd.conf | grep DocumentRoot
  
DocumentRoot "/var/lib/rinkai/public"

 1.3. .htaccessファイルの作成

   # cd /var/lib/rinkai/public
      # vi  .htaccess

     ==================================================
     # # # # # #
     # Basic認証
     AuthType Basic
     AuthName "Please UserID and Password"
     AuthUserFile /var/www/html/master/.htpasswd
     Require valid-user
   ==================================================

 1.4. htpasswdファイルの作成(コマンド実行により作成される)
     # htpasswd -c -b .htpasswd ユーザ名 パスワード

    1.5. .htpasswdファイルの存在確認(隠しファイル ls -a)
     # ls -a

  -rw-r--r-- 1 apache apache 121 6月 19 23:56 .htaccess
  -rw-r--r-- 1 apache apache 43 6月 19 23:46 .htpasswd

    1.6. apache再起動
     # service httpd restart