Nginx 홈페이지 암호설정
특정 URL 및 홈페이지 전체에 접근시 사용자이름 및 암호를 입력받게 설정하는
방법에 대한 글입니다.
ubuntu 14.04
nginx version: nginx/1.4.6
1.apache2-utils 를 설치
1 |
apt-get install apache2-utils |
2.계정과 비밀번호 생성
1 2 3 4 5 6 7 |
htpasswd -c /etc/nginx/.htpasswd userid New password: Re-type new password: Adding password for user userid cat /etc/nginx/.htpasswd userid:$apr1$IR9ZCLnj$Giwo8rkINpIvaKY.0wanq. |
3.nginx 설정
location 블럭에 추가합니다.
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
cat /etc/nginx/sites-enabled/default server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /www/html/wordpress; index index.html index.htm index.php; client_max_body_size 2048m; server_name localhost; include hhvm.conf; location / { auth_basic "Restricted"; auth_basic_user_file /etc/nginx/.htpasswd; client_max_body_size 2048m; try_files $uri $uri/ /index.php?$args; } } |
4.nginx restart
5.test