Blog スタッフブログ

システム開発

[サーバー系]NginxでのBasic認証のかけ方

システム開発担当のTFです。

やり方

  • .htpasswd ファイルを作成し任意のパスに配置する
  • nginx.conf や sites-available でbasic認証を設定する

メモ

Nginx は .htaccess が使えない
そのため、 nginx.conf や sites-available での設定が必要

サンプル

	# 省略
	server {
		listen 80;
		server_name  _;
		root   /usr/share/nginx/html;
		index  index.php index.html;

		location / {
			# basic認証設定 auth_basic_user_file は.htpasswd のパス
			auth_basic "basic authentication";
			auth_basic_user_file "/etc/nginx/.htpasswd";
		}

	}