N's Story

리눅스 아파치 웹서버 접속제한 설정(.htaccess) 본문

■ Communications /↘ Linux

리눅스 아파치 웹서버 접속제한 설정(.htaccess)

AndrewNa 2019. 12. 26. 19:07
728x90
반응형

개요
Web page 에 보안설정을 적용하여 허용된 사용자만 ID와 Password를 입력하여 접근 가능

 

 

절차

httpd.conf 파일 확인

.htaccess 파일 생성 및 설정
.htpasswd 파일 생성 및 설정
웹서버 Restart

 


세부 절차

​1. httpd.conf 파일 설정

웹 페이지 인증할 경로 설정

ex) /www

 

<Directory "/www">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

</Directory>

 

httpd.conf 파일내 htaccess 활성화 되어있는지 확인(주석 되어있으면 제거)

AccessFileName .htaccess

 

2. htaccess 파일 생성 및 설정

보안 인증을 적용할 디렉토리에서 .htaccess 파일 생성

# touch .htaccess // 숨김파일로 생성
# ls -al // 생성 파일 확인

# vi .htaccess // 파일 편집


--------------------------------------------------------------------------------------
AuthName "인증시도 문구" // 인증창 문구에 뜰 내용
AuthType Basic// 인증 방식(Basic/Digest)
AuthUserFile /www/.htpasswd // 인증 적용할 경로

(.htaccess : 인증요구, .htpasswd : 인증확인)

Require user ID // 인증 허용할 user id
ErrorDocument 401 "인증 실패시 문구" // 인증 실패시 문구
// 접근 제한 설정

 

<Limit GET POST>
require valid-user // 인증된 사용자만 접근 가능
# order deny, allow // 적용 순서로 거부 이후에 허용
# deny from all // 모두 거부
# allow from ip // 허용 ip

</Limit>
// 접근 제한 설정 종료
--------------------------------------------------------------------------------------

 

3. htpasswd 파일 생성 및 설정
# htpasswd -c .htpasswd ID // 최초 계정 ID생성(추가 생성시 -c 옵션 제거)
Adding password for ID
New password: Password 입력
Re-type new password: Password 재입력

 

 

4. 웹서버 Restart

service httpd restart // Web서버 재시작

or # (httpd 경로) restart

 

 

 

OS : CentOS 6.9

 

 

728x90
반응형
Comments