nginxでBasic認証の設定について1
.htpasswdファイルの設置
Basic認証で使う.htpasswdファイルを作成します。
# touch /usr/share/nginx/.htpasswd
# chown nginx:nginx /usr/share/nginx/.htpasswd
# htpasswd /usr/share/nginx/.htpasswd hogehogeuser
New password:(hogehogeuserに対するパスワードを入力)
Re-type new password:(hogehogeuserに対するパスワードをもう一度入力)
これで、/usr/share/nginx/ディレクトリに、.htpasswdファイルが作成されました。
nginxのconfファイルの編集
Basic認証を利用したいサイトのnginx用confファイルを修正します。
# vim /etc/nginx/conf.d/hogehoge.com.conf
+++++以下、hogehoge.com.confファイルの中身+++++
server {
listen 80;
server_name hogehoge.com;
root /usr/share/nginx/hogehoge;
index index.php;
location / {
auth_basic "Authentication";
auth_basic_user_file /usr/share/nginx/.htpasswd;
+++++以下略+++++