Traefik HTTP 라우터
Traefik HTTP 라우터 (Router)
본문
Router
HTTP Router
HTTP 라우터는 들어오는 요청을 처리할 수 있는 서비스에 연결하는 역할을 담당해요. 라우터는 규칙을 기준으로 들어오는 요청을 분석하고, 매칭되면 설정된 미들웨어를 거쳐 적절한 서비스로 요청을 전달해요.
Configuration Example (설정 예시)
Structured (YAML)
http:
routers:
my-router:
entryPoints:
- "web"
- "websecure"
rule: "Host(`example.com`) && Path(`/api`)"
priority: 10
middlewares:
- "auth"
- "ratelimit"
tls:
certResolver: "letsencrypt"
options: "modern"
domains:
- main: "example.com"
sans:
- "www.example.com"
observability:
metrics: true
accessLogs: true
tracing: true
parentRefs:
- "parent-router-1"
- "parent-router-2"
service: my-service
Structured (TOML)
[http.routers]
[http.routers.my-router]
entryPoints = ["web", "websecure"]
rule = "Host(`example.com`) && Path(`/api`)"
priority = 10
middlewares = ["auth", "ratelimit"]
service = "my-service"
parentRefs = ["parent-router-1", "parent-router-2"]
[http.routers.my-router.tls]
certResolver = "letsencrypt"
options = "modern"
[[http.routers.my-router.tls.domains]]
main = "example.com"
sans = ["www.example.com"]
[http.routers.my-router.observability]
metrics = true
accessLogs = true
tracing = true
Labels
labels:
- "traefik.http.routers.my-router.entrypoints=web,websecure"
- "traefik.http.routers.my-router.rule=Host(`example.com`) && Path(`/api`)"
- "traefik.http.routers.my-router.priority=10"
- "traefik.http.routers.my-router.middlewares=auth,ratelimit"
- "traefik.http.routers.my-router.service=my-service"
- "traefik.http.routers.my-router.tls.certresolver=letsencrypt"
- "traefik.http.routers.my-router.tls.options=modern"
- "traefik.http.routers.my-router.tls.domains[0].main=example.com"
- "traefik.http.routers.my-router.tls.domains[0].sans=www.example.com"
- "traefik.http.routers.my-router.observability.metrics=true"
- "traefik.http.routers.my-router.observability.accessLogs=true"
- "traefik.http.routers.my-router.observability.tracing=true"
Tags
{
"Tags": [
"traefik.http.routers.my-router.entrypoints=web,websecure",
"traefik.http.routers.my-router.rule=Host(`example.com`) && Path(`/api`)",
"traefik.http.routers.my-router.priority=10",
"traefik.http.routers.my-router.middlewares=auth,ratelimit",
"traefik.http.routers.my-router.service=my-service",
"traefik.http.routers.my-router.tls.certresolver=letsencrypt",
"traefik.http.routers.my-router.tls.options=modern",
"traefik.http.routers.my-router.tls.domains[0].main=example.com",
"traefik.http.routers.my-router.tls.domains[0].sans=www.example.com",
"traefik.http.routers.my-router.observability.metrics=true",
"traefik.http.routers.my-router.observability.accessLogs=true",
"traefik.http.routers.my-router.observability.tracing=true",
]
}
Configuration Options (설정 옵션)
| Field | Description | Default | Required |
| entryPoints | 라우터가 연결되는 엔트리포인트 목록이에요. 지정하지 않으면 HTTP 라우터는 모든 엔트리포인트에 연결돼요. | All entry points | No |
| rule | 규칙은 특정 요청이 특정 기준과 일치하는지 판단하도록 값으로 구성된 매처(matcher) 집합이에요. 규칙이 검증되면 라우터가 활성화되고, 미들웨어를 호출한 뒤 요청을 서비스로 전달해요. 자세한 내용은 Rules & Priority를 참고해 주세요. | | Yes |
| priority | 경로 중복을 피하기 위해 라우트는 기본적으로 규칙 길이를 기준으로 내림차순 정렬돼요. 우선순위는 규칙의 길이와 정확히 같으므로, 길이가 가장 긴 규칙이 가장 높은 우선순위를 가져요. 우선순위 값 0은 무시돼요. 음수 값도 지원돼요. 자세한 내용은 Rules & Priority를 참고해 주세요. | Rule length | No |
| middlewares | 라우터에 적용되는 미들웨어 목록이에요. 미들웨어는 선언된 순서대로 적용돼요. 사용 가능한 미들웨어는 Middlewares overview를 참고해 주세요. | | No |
| tls | 라우터의 TLS 구성이에요. 지정하면 라우터는 HTTPS 요청만 처리해요. | | No |
| tls.certResolver | 자동 인증서 생성을 위해 사용할 인증서 리졸버 이름이에요. 자세한 내용은 Certificate Resolver를 참고해 주세요. | | No |
| tls.options | TLS 파라미터(암호화 스위트, 최소/최대 TLS 버전, 클라이언트 인증 등)를 구성하는 데 사용할 TLS 옵션 이름이에요. 이 값은 라우터 자체가 아니라 라우터 규칙의 호스트 이름에 매핑되므로, 같은 엔트리포인트에서 같은 호스트 이름을 제공하는 모든 라우터는 동일한 TLS 옵션을 참조해야 해요. 상세 구성은 TLS Options를, 그렇게 하지 않을 때의 영향은 Conflicting TLS Options를 참고해 주세요. | default | No |
| tls.domains | 명시적 인증서 도메인 지정을 위한 도메인 및 Subject Alternative Names(SAN) 목록이에요. ACME 인증서 리졸버를 사용할 때 도메인은 라우터 규칙에서 자동으로 추출되므로 이 옵션은 선택 사항이에요. | | No |
| observability | 라우터의 관측성 구성이에요. 라우터별로 액세스 로그, 메트릭, 트레이싱을 세밀하게 제어할 수 있어요. 자세한 내용은 Observability를 참고해 주세요. | Inherited from entry points | No |
| observability.traceVerbosity | 이 라우터의 트레이싱 상세 수준을 정의해요. 허용 값은 minimal과 detailed예요. | minimal | No |
| parentRefs | 멀티 레이어 라우팅을 위한 부모 라우터 이름 참조예요. 지정하면 이 라우터는 부모 라우터가 미들웨어를 적용한 뒤에 요청을 처리하는 자식 라우터가 돼요. 자세한 내용은 Multi-Layer Routing을 참고해 주세요. | | No |
| service | 매칭된 요청을 처리할 서비스 이름이에요. 서비스는 로드 밸런서, 가중치 라운드 로빈, 미러링, 또는 페일오버 서비스일 수 있어요. 자세한 내용은 Service를 참고해 주세요. | | Yes |
Router Naming (라우터 이름 규칙)
-
라우터 이름에
@문자는 허용되지 않아요. -
provider별 구성(Docker, Kubernetes)에서는 라우터 이름이 서비스 이름과 규칙을 기반으로 자동 생성되는 경우가 많아요.
프로덕션에서 Traefik OSS를 사용하시나요?
직장에서 Traefik을 사용하고 있다면, 엔터프라이즈급 API 게이트웨이 기능이나 Traefik OSS에 대한 상용 지원을 고려해 보세요.
-
API 게이트웨이 데모 영상 보기
-
24/7/365 OSS 지원 요청하기
Traefik OSS에 API 게이트웨이 기능을 추가하는 것은 빠르고 자연스러워요. 기존 구성을 갈아엎거나 교체할 필요 없이 모든 설정이 그대로 유지돼요. 이 짧은 영상에서 직접 확인해 보세요.