ConohaのVPSにBASIC認証を設定してみた。

ConohaのVPSBASIC認証を設定してみた。

用意するもの

.htaccessの記述例

AuthUserFileには.htpasswdを設置したディレクトリのフルパスを記述する。

AuthUserFile /FULL_PATH/.htpasswd
AuthGroupFile /dev/null
AuthName "Please Enter your ID & Password"
AuthType Basic
require valid-user

<Files ~ "^.(htpasswd|htaccess)$">
 Order allow,deny
 Deny from all
 Satisfy All
</Files>
.htpasswdの記述例

次のWebサイトから.htpasswdを自動生成し、VPS上に用意した.htpasswdにコピペする
tech-unlimited.com

VPShttpd.confの修正

httpd.confのAllowOverrideをAllに変更

<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>

Apacheの再起動

systemctl restart httpd

終わり。