Categories
Computer Network

아파치 (Apache) 에서 암호로 디렉토리 보호하기

1. 암호 파일 생성

“/etc/apache2” 디렉토리에 암호 파일을 만든다.

sudo htpasswd -c /etc/apache2/.htpasswd user12

“user12” 는 로그인에 사용될 사용자이름이다.

htpasswd 명령은 암호를 2 번 입력받는다.

2. 000-default.conf 파일 편집

“000-default.conf” 파일을 연다.

sudo vi /etc/apache2/sites-enabled/000-default.conf

파일에서 아래 라인을 찾는다.

AllowOverride None

“None” 을 “All” 로 변경한다.

AllowOverride All

파일을 저장하고 편집기를 닫는다.

아파치 (Apache) 를 재시작한다.

sudo systemctl restart apache2.service

3. 디렉토리에 암호 설정하기

암호로 보호할 디렉토리로 이동한다.

cd /test/html/admin

편집기로 “.htaccess” 파일을 생성한다.

sudo vi .htaccess

파일에 아래 내용을 입력한다.

AuthType Basic
AuthName "Password Required"
Require valid-user
AuthUserFile /etc/apache2/.htpasswd

4. 결과 확인

웹브라우저에서 암호가 설정된 디렉토리를 연다.

https://example.com/admin

로그인을 위한 팝업 (pop-up) 창이 열리는지 확인한다.

Leave a Reply

Your email address will not be published. Required fields are marked *