본문 바로가기
  • Code Smell
Web

[Apache2.4] 특정 IP access 관리 (Apache Allow IP)

by HSooo 2019. 5. 28.

[Apache2.4]특정 IP access 관리 (Apache Allow IP)

Apache 2.4 아래 버전과 2.4 부터 설정 방법에 차이가 있다. 여기서는 2.4 버전 설정을 한다.
예를들어 htdocs를 DocumentRoot로 잡고
DocumentRoot "D:/htdocs"

htdocs 하위폴더에 아래와 같이 존재할때
htdocs/subdir1
htdocs/subdir2
htdocs/subdir3

모든IP에 대해 허용

<Directory "D:/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
  • 상위 디렉토리에 대해 접근설정을 해놓으면 하위디렉토리가 따로 override 하지 않는 한 동일함.
  • 즉 위와 같이 설정하면 subdir1, subdir2, subdir3 도 접근이 가능하다.

디렉토리 인덱싱을 제거하려면 Options의 내용을 빼면 된다.

<Directory "D:/htdocs">
    Options
    AllowOverride None
    Require all granted
</Directory>

모든IP에 대해 차단

<Directory "D:/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

특정 IP에 대해 허용

<Directory "D:/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require ip 123.123.123.123
</Directory>
  • 접근 IP만 설정해도 기본적으로 2.4 버전 아래의 Deny from all 과 같은 설정이 들어가 있으며 특정 IP만 여는 경우 해당 IP 리스트를 제외하고는 접근이 불가능하다.
  • subdir 들에게도 적용된다. (123.123.123.123 IP만 subdir1, subdir2, subdir3 접근)
  • Require ip 는 여러개 쓸수 있음.

로컬 IP만 접근 허용

<Directory "D:/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require ip ::1
</Directory>
  • 127.0.0.1 또는 localhost 등이 아님.

대역으로 오픈

<Directory "D:/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require ip 123.123.123
</Directory>
  • 123.123.123.0 ~ 123.123.123.255 까지 접근 가능하다.

bit 대역으로 오픈

<Directory "D:/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None

    # 123.123.123.0 ~ 123.123.123.255
    Require ip 123.123.123.0/24

    # 123.123.123.0 ~ 123.123.123.127
    Require ip 123.123.123.0/25
</Directory>
  • bit연산으로 대역설정이 가능

서브디렉토리 권한 override

Directory 태그 아래 추가로 작성해주면 된다.

<Directory "D:/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require ip ::1
    Require ip 123.123.123.0/24
</Directory>

<Directory "D:/htdocs/subdir1">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require ip ::1
    Require ip 123.123.123.122
</Directory>

위와 같이 설정 시


IP : 127.0.0.1, 123.123.123.122 는

htdocs/
htdocs/subdir1
htdocs/subdir2
htdocs/subdir3

이렇게 접근 가능하다.


IP : 127.0.0.1, 123.123.123.0 ~ 123.123.123.255 는

htdocs/
htdocs/subdir2
htdocs/subdir3

이렇게 접근 가능하다.


htdocs/subdir1 는 로컬, 123.123.123.122 만 접근 가능

  • 하위 디렉토리별로 다시 써주면 해당 IP만 따로 설정이 가능함.
  • 위와 같이 설정한 경우 htdocs/subdir1/* (subdir1 하위폴더) 도 123.123.123.122만 접근 가능함.

댓글