Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
197
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

Organization

Nginx で Basic 認証

パッケージインストール

htpasswd コマンドを利用するため、下記のパッケージをインストール。

Debian 系

$ sudo apt-get install apache2-utils

Red Hat 系

$ sudo yum install httpd-tools

.htpasswd ファイルの作成

ユーザ名とパスワードを追加。

$ sudo htpasswd -c /etc/nginx/.htpasswd username
New password: password
Re-type new password: password
Adding password for user username

nginxの設定ファイルの追記

.htpasswd ファイルを読み込み、Basic 認証を適用。

$vim /etc/nginx/nginx.conf
…
server {
    listen 80;
    root /usr/share/nginx/html;
    index index.html index.htm;

    location / {
        auth_basic "Restricted";                   # 認証時に表示されるメッセージ
        auth_basic_user_file /etc/nginx/.htpasswd; # .htpasswdファイルのパス
    }
}
…

再起動

sudo service nginx restart
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
197
Help us understand the problem. What are the problem?