라이브러리

[NGINX] tcp_keepalive - TCP 연결의 KeepAlive 동작을 설정합니다.


NGINX에서 tcp_keepalive는 TCP 연결을 유지하기 위한 옵션입니다. TCP Keepalive는 연결이 끊어지지 않도록 유지하기 위해 주기적으로 패킷을 보내는 기능입니다.

NGINX에서 tcp_keepalive를 설정하는 방법은 다음과 같습니다.

NGINX 구성 파일에서 tcp_keepalive 설정


NGINX 구성 파일에서 tcp_keepalive를 설정하는 방법은 다음과 같습니다.

#hostingforum.kr
bash

http {

    ...

    keepalive_timeout 65;

    keepalive_requests 100;

    keepalive_headers_timeout 5;

    keepalive_idle_timeout 65;

    ...

}



- `keepalive_timeout`: Keepalive가 활성화된 후 연결이 끊어지지 않도록 유지하는 시간입니다. 기본값은 65초입니다.
- `keepalive_requests`: Keepalive가 활성화된 후 요청이 발생할 수 있는 횟수입니다. 기본값은 100입니다.
- `keepalive_headers_timeout`: Keepalive가 활성화된 후 헤더가 유지되는 시간입니다. 기본값은 5초입니다.
- `keepalive_idle_timeout`: Keepalive가 활성화된 후 연결이 유지되지 않도록 유지하는 시간입니다. 기본값은 65초입니다.

NGINX 구성 파일에서 tcp_keepalive 설정 예제


NGINX 구성 파일에서 tcp_keepalive를 설정하는 예제는 다음과 같습니다.

#hostingforum.kr
bash

http {

    ...

    server {

        listen 80;

        server_name example.com;



        location / {

            proxy_pass http://localhost:8080;

            proxy_set_header Host $host;

            proxy_set_header X-Real-IP $remote_addr;

        }



        keepalive_timeout 120;

        keepalive_requests 200;

        keepalive_headers_timeout 10;

        keepalive_idle_timeout 120;

    }

    ...

}



- 위 예제에서는 Keepalive가 활성화된 후 연결이 끊어지지 않도록 유지하는 시간을 120초로 설정하고, Keepalive가 활성화된 후 요청이 발생할 수 있는 횟수를 200으로 설정했습니다.

NGINX에서 tcp_keepalive 설정 확인


NGINX에서 tcp_keepalive 설정을 확인하는 방법은 다음과 같습니다.

#hostingforum.kr
bash

nginx -t



- 위 명령어를 실행하면 NGINX 구성 파일의 유효성을 확인하고, Keepalive 설정이 올바르게 적용되었는지 확인할 수 있습니다.

NGINX에서 tcp_keepalive 설정 적용 확인


NGINX에서 tcp_keepalive 설정을 적용 확인하는 방법은 다음과 같습니다.

#hostingforum.kr
bash

nginx -s reload



- 위 명령어를 실행하면 NGINX 구성 파일의 변경 사항이 반영되고, Keepalive 설정이 적용됩니다.

NGINX에서 tcp_keepalive 설정 취소


NGINX에서 tcp_keepalive 설정을 취소하는 방법은 다음과 같습니다.

#hostingforum.kr
bash

http {

    ...

    server {

        listen 80;

        server_name example.com;



        location / {

            proxy_pass http://localhost:8080;

            proxy_set_header Host $host;

            proxy_set_header X-Real-IP $remote_addr;

        }



        # Keepalive 설정을 취소합니다.

        keepalive_timeout 0;

        keepalive_requests 0;

        keepalive_headers_timeout 0;

        keepalive_idle_timeout 0;

    }

    ...

}



- 위 예제에서는 Keepalive 설정을 취소했습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 26 페이지

검색

게시물 검색