LoginSignup
1
4

More than 5 years have passed since last update.

ELB x EC2のステージング環境でのApacheでBasic認証をかける場合

Last updated at Posted at 2016-03-03

基礎的なことですが、ハマってしまったので振り返りメモとして残します

環境

ELB
EC2
Apache 2.4

用途

CakePHPのステージング環境

その他

ELBのヘルスチェックは/favicon.ico

やりたかったこと

Basic認証をかける
app/webroot配下の.htaccessには追記したくない
=> ansibleで構成管理してるのでステージング環境だけconf.d配下にbasic認証用の設定をfileモジュールで追加したい

ハマったこと

ELBのヘルスチェックもbasic認証にひっかかる
それに気づかず設定に苦戦する
(´-`).。oO(よく見たらaccess_logにHTTP 401が沢山吐かれてた・・)

最終的な設定

EBLのヘルスチェック回避する為にSatisfy Anyを利用するようconf.d配下に以下の設定ファイルを追加

/etc/httpd/conf.d/auth_basic.conf
<Directory /var/www/hoge/current/app/webroot>
    Satisfy Any

    AuthType Basic
    AuthName "Basic Auth"
    AuthUserFile /etc/httpd/.htpasswd
    Require valid-user

    SetEnvIf Request_URI "/favicon.ico" healthcheck
    Order Deny,Allow
    Deny from all
    Allow from env=healthcheck
</Directory>

htpasswd作成

sudo htpasswd -c /etc/httpd/.htpasswd username

Apacheの再起動

sudo service httpd restart

所感

ちゃんとSSL証明書をELBに入れて本番環境とほぼ一緒の構成にしてたので、普段のようにステージング環境にさくっとBasic認証かけてーというところでハマりましたが、振り返るとそりゃそうだよね・・
(´-`).。oO(Nginx x PHP-FPMに載せ換えたいなぁ・・)

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4