LoginSignup
2
3

More than 5 years have passed since last update.

nginx ベーシック認証

Posted at

htpasswdコマンドで.htpasswdファイルを作成しようとしたが、コマンドが存在しないとのこと。

どうやらhtpasswdコマンドはApache付属のコマンドらしいので、httpd-toolsをインストールする。

$ sudo yum install httpd-tools

さて打ってみる。

$ sudo htpasswd -c /var/www/html/.htpasswd password

パスワードを聞かれ入力し、無事にhtpasswdファイルを作成完了。

設定ファイルを開く。

$ sudo vim /etc/nginx/nginx.conf

設定を追加。

server {
    auth_basic "Restricted";
    auth_basic_user_file /var/www/html/.htpasswd;
}

nginxを再起動。

$ systemctl restart nginx

ブラウザで該当のURLにアクセスすると、ベーシック認証を聞かれた。成功。

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