728x90
반응형

특정 디렉토리 이하에 대해서 접근을 제어하고자 할 때에는 .htaccess 를 사용하거나 httpd.conf 에서 <Directory> 를 이용하여 제어를 할 수 있지만, 만약 특정한 파일에 대해서 외부에서의 접근을 제한하고자 한다면 어떻게 하여야 할까? 
이때에는 Location 을 사용하면 된다. httpd.conf 파일에 아래와 같이 설정시 모든 디렉토리 이하의 secret.html 파일에 대해서는 192.168.1.1 에서만 접근이 가능하게 된다.

# httpd.conf  
#<Directory>로 안될경우가 있는데 이때 secret.html 대신 디렉토리를 써주면 디렉토리도 가능하다.
# 왜 안되는지는 잘 모르겠다...ㅡ.ㅡ;;
<Location /secret.html>
order deny,allow
deny from all
allow from 192.168.1.1
</Location>

만약 여러 도메인이 설치되어 있는 호스팅 서버의 경우 secret.tt.co.kr 도메인내 secret.html 에 대해서만 접근을 제어하고자 할 경우에는 아래와 같이 VirtualHost 설정에서 하면 된다.

<VirtualHost secret.domain.co.kr>
ServerAdmin anti@domain.co.kr
DocumentRoot /usr/local/apache/htdocs/secret/
ServerName secret.tt.co.kr
<Location /secret.html>
order deny,allow
deny from all
allow from 192.168.1.1 
</Location>
</VirtualHost>

또는 위와 같이 IP 가 아니라 특정한 ID/PW를 입력한 유저에 대해서만 특정 파일에 대하여 접근을 허용하고자 할 때가 있다. 이러한 경우에는 httpd.conf 에 아래와 같이 설정하면 된다.

<VirtualHost secret.domain.co.kr>
ServerAdmin anti@domain.co.kr
DocumentRoot /usr/local/apache/htdocs/secret/
ServerName secret.tt.co.kr
<Files secret.html>
AuthName "ID/PW 를 입력하세요."
AuthType Basic
AuthUserFile /usr/local/apache/htdocs/.htpasswd
Require valid-user
</Files>
</VirtualHost>

그리고 htpasswd –c .htpasswd id 로 .htpasswd 파일에 ID/PW를 생성하여 secret.html 에 접근시 ID/PW 를 정확히 입력한 유저에 대해서만 접근이 가능하게 된다.
 
728x90
반응형

+ Recent posts