参考:http://bekkou68.hatenablog.com/entry/2013/10/05/232451
任意の場所へ
cd /etc/nginx/conf.d/
sudo htpasswd -c .htpasswd username
ドットファイルにする方がセキュリティが良い気がする。
パスワードの設定を求められるので、パスワードを2回入力する(この入力したパスワードがログイン時に実際に使用するもので、ファイルに出力されるのはcrypt関数で暗号化されているので簡単に復号化はできないらしい。パスワード忘れてしまった場合はユーザー追加しか対応がないのかな。
ユーザーを追加したい場合、
sudo htpasswd .htpasswd addusername
パスワード生成コマンドlinux
mkpasswd
pwgen
http://d.hatena.ne.jp/tkrd/20121111/1352645711
nginx設定例:
server {
listen 80;
server_name ;
location / {
# Passwd auth
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
root ;
}
location /nginx_status {
stub_status on; # activate stub_status module
access_log off;
allow 127.0.0.1; # restrict access to local only
deny all;
}
}
設定反映
nginx -t
sudo service nginx reload