68
67

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nginxでBasic認証をする

Last updated at Posted at 2015-01-07

##やりたいこと
nginxでBasic認証をかける

##手順

① htpasswdコマンドを利用するためにhttpd-toolsを入れる

$ yum install -y httpd-tools

② Basic認証のユーザー・パスワードを設定

$ cd /etc/nginx
$ htpasswd -c .htpasswd hoge
New password: ユーザーhogeのパスワード
Re-type new password: もういちど入力

③ nginxの設定ファイルでBasic認証を有効にする

/etc/nginx/conf.d/default.conf
server {
	listen 80;
	server_name example.com;

	root /path/to/public;

	location / {
		auth_basic "Restricted";
		auth_basic_user_file /etc/nginx/.htpasswd;
	}
}
  • auth_basic_user_fileには②で作成したBasic認証用ファイルのパスを指定
  • 特定のパスにBasic認証をかけたいときは、"location / "を適宜変更する

④ ブラウザで確認
 Basic認証をかけたURLへアクセスし、認証が有効になっているか確認する.

68
67
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
68
67

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?