Help us understand the problem. What is going on with this article?

Nginx で Basic 認証

More than 3 years have passed since last update.


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


.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
想いをつなぎ、叶える未来を、つくる READYFORのOrganizationです
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