본문 바로가기

리눅스

Apache Method 예외처리

728x90

Apache Method 예외처리

HTTP는 요청 메서드를 정의하여, 주어진 리소스에 수행하길 원하는 행동을 나타냅니다. 간혹 요청 메서드를 "HTTP 동사"라고 부르기도 합니다. 각각의 메서드는 서로 다른 의미를 구현하지만, 일부 기능은 메서드 집합 간에 서로 공유하기도 합니다. 이를테면 응답 메서드는 안전하거나, 캐시 가능하거나, 멱등성을 가질 수 있습니다.

 

  • GET
    • GET 메서드는 특정 리소스의 표시를 요청합니다. GET을 사용하는 요청은 오직 데이터를 받기만 합니다.
  • HEAD
    • HEAD 메서드는 GET 메서드의 요청과 동일한 응답을 요구하지만, 응답 본문을 포함하지 않습니다.
  • POST
    • POST 메서드는 특정 리소스에 엔티티를 제출할 때 쓰입니다. 이는 종종 서버의 상태의 변화나 부작용을 일으킵니다.
  • PUT
    • PUT 메서드는 목적 리소스 모든 현재 표시를 요청 payload로 바꿉니다.
  • DELETE
    • DELETE 메서드는 특정 리소스를 삭제합니다.
  • CONNECT
    • CONNECT 메서드는 목적 리소스로 식별되는 서버로의 터널을 맺습니다.
  • OPTIONS
    • OPTIONS 메서드는 목적 리소스의 통신을 설정하는 데 쓰입니다.
  • TRACE
    • TRACE 메서드는 목적 리소스의 경로를 따라 메시지 loop-back 테스트를 합니다.
  • PATCH
    • PATCH 메서드는 리소스의 부분만을 수정하는 데 쓰입니다.

허용할 method 정의(LimitExcept 지시자)

$ vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
...
<Directory "/usr/local/apache2/docs/test.sangchul.kr">
  <LimitExcept GET POST>
    Order deny,allow
    Deny from all
  </LimitExcept>
  Require all granted
</Directory>
  • GET POST 메소드만 허용
728x90

 

cURL 적용 테스트

curl -X BOGUS --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
$ curl -X BOGUS --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
HTTP/1.1 403 Forbidden
Date: Thu, 26 Nov 2020 08:48:35 GMT
Server: Apache
Content-Length: 209
Content-Type: text/html; charset=iso-8859-1
curl -X GET --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
$ curl -X GET --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
HTTP/1.1 200 OK
Date: Thu, 26 Nov 2020 08:48:43 GMT
Server: Apache
Content-Length: 55
Content-Type: text/html; charset=UTF-8

제한할 method 정의(Limit 지시자)

vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
$ vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
...
<Directory "/usr/local/apache2/docs/test.sangchul.kr">
  <Limit DELETE PUT OPTIONS>
    Order allow,deny
    #Allow from all
    Deny from all
  </Limit>
  Require all granted
</Directory>
  • DELETE PUT OPTIONS 메소드만 제한
  • 웹에서 검색해보면 다른 사용자들은 "Allow from all" 제한이 되는 거 같은데, 저 같은 경우에는 적용이 안 되어서 "Deny from all"로 변경하여 테스트하였습니다.

cURL 적용 테스트

  • PUT 메소드
curl -X PUT --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
$ curl -X PUT --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
HTTP/1.1 403 Forbidden
Date: Thu, 26 Nov 2020 08:56:05 GMT
Server: Apache
Content-Length: 209
Content-Type: text/html; charset=iso-8859-1
  • GET 메소드
curl -X GET --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
$ curl -X GET --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
HTTP/1.1 200 OK
Date: Thu, 26 Nov 2020 09:00:56 GMT
Server: Apache
Content-Length: 55
Content-Type: text/html; charset=UTF-8
  • BOGUS 메소드(임의의 문자열)
curl -X BOGUS --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
$ curl -X BOGUS --resolve 'test.sangchul.kr:80:123.123.123.123' -I http://test.sangchul.kr
HTTP/1.1 200 OK
Date: Fri, 27 Nov 2020 00:42:23 GMT
Server: Apache
Content-Length: 55
Content-Type: text/html; charset=UTF-8

 

참고URL

- https://developer.mozilla.org/ko/docs/Web/HTTP/Methods

- 자바공작소 : HTTP 응답코드 메소드 정리 GET, POST, PUT, PATCH, DELETE, TRACE, OPTIONS

 

728x90