관리 메뉴

피터의 개발이야기

[Linux] curl을 사용하여 HTTP 헤더를 확인 방법 본문

Linux

[Linux] curl을 사용하여 HTTP 헤더를 확인 방법

기록하는 백앤드개발자 2025. 3. 15. 07:07
반응형

ㅁ 들어가며

[Nginx] NGINX에서 정적 파일 캐시 설정하는 방법을 알아보면서 HTTP 헤더의 확인이 필요하였다.

 

ㅁ 헤더만 보기 (-I 옵션)

$ curl -I http://example.com
HTTP/1.1 200 OK
Content-Type: text/html
ETag: "84238dfc8092e5d9c0dac8ef93371a07:1736799080.121134"
Last-Modified: Mon, 13 Jan 2025 20:11:20 GMT
Cache-Control: max-age=1190
Date: Sun, 09 Mar 2025 14:46:37 GMT
Connection: keep-alive

 

ㅁ 헤더와 본문 함께 보기 (-i 옵션)

$ curl -i http://example.com
HTTP/1.1 200 OK
Content-Type: text/html
ETag: "84238dfc8092e5d9c0dac8ef93371a07:1736799080.121134"
Last-Modified: Mon, 13 Jan 2025 20:11:20 GMT
Cache-Control: max-age=801
Date: Sun, 09 Mar 2025 14:48:58 GMT
Content-Length: 1256
Connection: keep-alive

<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 2em;
        background-color: #fdfdff;
        border-radius: 0.5em;
        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
    @media (max-width: 700px) {
        div {
            margin: 0 auto;
            width: auto;
        }
    }
    </style>
</head>

<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is for use in illustrative examples in documents. You may use this
    domain in literature without prior coordination or asking for permission.</p>
    <p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>

 이 명령은 응답 헤더와 본문을 모두 표시된다.

 

 

ㅁ 상세 정보 보기 (-v 옵션)

$ curl -v http://example.com
*   Trying 23.192.228.80:80...
* Connected to example.com (23.192.228.80) port 80
~~~ 생략 ~~~
* Connection #0 to host example.com left intact

ㅇ 이 옵션은 요청 및 응답 헤더를 포함한 자세한 정보를 표시

 

ㅁ HTTPS 사이트의 경우

$ curl -k -I https://example.com
HTTP/2 200
content-type: text/html
etag: "84238dfc8092e5d9c0dac8ef93371a07:1736799080.121134"
last-modified: Mon, 13 Jan 2025 20:11:20 GMT
cache-control: max-age=1200
date: Sun, 09 Mar 2025 15:05:28 GMT
alt-svc: h3=":443"; ma=93600,h3-29=":443"; ma=93600,quic=":443"; ma=93600; v="43"

ㅇ -k 옵션은 SSL 인증서 검증을 건너뛰어 HTTPS 사이트의 헤더를 확인할 수 있다.

 

ㅁ 특정 HTTP 메소드 사용

$ curl -X GET -I http://example.com
HTTP/1.1 200 OK
Content-Type: text/html
ETag: "84238dfc8092e5d9c0dac8ef93371a07:1736799080.121134"
Last-Modified: Mon, 13 Jan 2025 20:11:20 GMT
Cache-Control: max-age=767
Date: Sun, 09 Mar 2025 15:06:17 GMT
Content-Length: 1256
Connection: keep-alive

 

ㅁ 함께 보면 좋은 사이트

CURL 명령어 사용법 💯 완전 총정리

[Linux] - Curl 명령어

반응형
Comments