- */etc/nginx/*に移動する
- 出力先のディレクトリオーナーがrootになっているので
tee
コマンドを使ってリダイレクトする
$ cd /etc/nginx/
$ print "USER:$(openssl passwd -crypt PASSWORD)\n" | sudo tee .htpasswd
- .confファイルに.htpasswdへのパスを指定
- BASIC認証をかけるパスを指定する
$ cd /etc/nginx/sites-available
$ sudo vim hoge.com.conf
server {
listen 80;
server_name hoge.com;
root /var/www/hoge.com/root/htdocs/;
index index.html index.php;
access_log /var/log/nginx/hoge.com.access.log;
error_log /var/log/nginx/hoge.com.error.log;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$uri&$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /PATH/ {
auth_basic "admin only";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
- nginxを再起動して設定を反映させる
$ sudo service nginx restart
終わり