LoginSignup
10
11

More than 1 year has passed since last update.

Nginx で Basic 認証

Last updated at Posted at 2019-05-08

Nginx で Basic 認証をする方法です。

http://hostname/qiita に Basic 認証をかけるとすると、

1. /etc/nginx/nginx.conf に追加

/etc/nginx/nginx.conf
(省略)
        location /qiita {
                root   /var/www;
                index  index.html index.htm;
                auth_basic "Restricted";
                auth_basic_user_file /etc/nginx/.htpasswd;
                }

2. パスワードファイルの作成

pass_gen
#! /bin/bash
#
USER=scott
PASSWD=tiger123
printf "$USER:$(openssl passwd -apr1 $PASSWD)\n" >> .htpasswd
#

できたファイルを /etc/nginx に置きます。
この方法で作成したパスワードは、8文字までが有効です。

3. Nginx の再起動

sudo systemctl restart nginx

確認したバージョン

$ nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
$ openssl version
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
10
11
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
10
11