Apache + Passenger で Basic 認証を設定したのでメモ。
myuser というユーザのパスワードファイルを作成する。
# htpasswd -c /usr/local/apache2/.htpasswd myuser |
# htpasswd -c /usr/local/apache2/.htpasswd myuser
Apache の設定ファイルを修正する。
# vim /usr/local/apache2/conf/extra/passenger.conf
<VirtualHost *:80>
PassengerUserSwitching off
PassengerDefaultUser app
ServerName example.com
DocumentRoot "/srv/example.com/current/public"
ErrorLog "logs/example.com-error_log"
CustomLog "logs/example.com-access_log" common
<Directory /srv/example.com/current/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
<Location />
AuthType Basic
AuthName "Please enter your ID and Password"
AuthUserFile /usr/local/apache2/.htpasswd
Require user myuser
</Location>
</VirtualHost> |
# vim /usr/local/apache2/conf/extra/passenger.conf
<VirtualHost *:80>
PassengerUserSwitching off
PassengerDefaultUser app
ServerName example.com
DocumentRoot "/srv/example.com/current/public"
ErrorLog "logs/example.com-error_log"
CustomLog "logs/example.com-access_log" common
<Directory /srv/example.com/current/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
<Location />
AuthType Basic
AuthName "Please enter your ID and Password"
AuthUserFile /usr/local/apache2/.htpasswd
Require user myuser
</Location>
</VirtualHost>
Apache の再起動
以上です。
【参考】
・@IT:Apacheでユーザー認証を行うには(Basic認証編) 
・blog.sowatchasayin: rails + passengerでbasic認証 