Listener rule của Application Load Balancer
Khi hệ thống tách thành nhiều service, một load balancer vẫn có thể đứng trước tất cả và chuyển từng request tới đúng service dựa trên đường dẫn hoặc tên miền.
MFTECH tách hệ thống thành service đơn hàng, service sản phẩm và các microsite khuyến mãi, mỗi thành phần có một target group riêng. Tất cả vẫn nằm sau một ALB. Mỗi request đi qua listener HTTPS: lựa chọn chứng chỉ (SNI), AWS WAF, sau đó listener rule khớp điều kiện (path, host) thực hiện các action của rule: xác thực (nếu có action authenticate) rồi forward tới target group. Chọn tình huống và gửi request:
Nhấn Gửi request để quan sát từng bước xử lý.
Ngoài path và host, listener rule có thêm bốn loại điều kiện: http-header, http-request-method, query-string và source-ip (dạng CIDR). Mỗi rule có priority; ALB xét rule từ giá trị priority nhỏ tới lớn, dừng ở rule đầu tiên khớp mọi điều kiện, và default rule luôn được xét cuối cùng. Action có thể là forward, redirect (301 hoặc 302; chuyển được HTTP sang HTTPS, không chuyển được HTTPS sang HTTP), fixed-response (trả mã 2XX, 4XX hoặc 5XX ngay tại ALB) hoặc authenticate. Chọn request và quan sát rule nào xử lý:
(mọi request còn lại)redirect 301 → HTTPS :443source-ip: 203.0.113.0/24path-pattern: /admin/*forward → TG adminpath-pattern: /admin/*fixed-response 403http-header: X-App-Platform: mobileforward → TG mobile-apiquery-string: version=betaforward → TG products-betahttp-request-method: POSTpath-pattern: /orders/*forward → TG orders-writepath-pattern: /orders/*forward → TG orderspath-pattern: /products/*forward → TG products(mọi request còn lại)forward → TG webChọn một request, sau đó nhấn Đánh giá rule. ALB xét các rule theo priority từ giá trị nhỏ tới lớn và dừng ở rule đầu tiên khớp mọi điều kiện.
- Listener rule định tuyến theo path (
/orders/*, không xét query string), host (*.mftech.vnkhớpkhuyenmai.mftech.vnnhưng không khớp tên miền gốcmftech.vn), header, method, query string và IP nguồn; rule có priority nhỏ hơn được xét trước. - Listener HTTP :80 dùng action redirect để chuyển sang HTTPS.
- ALB không có cơ chế giới hạn tốc độ request: liên kết AWS WAF và dùng rate-based rule (mặc định đếm theo IP nguồn, evaluation window 1, 2, 5 hoặc 10 phút, ngưỡng tối thiểu 10 request).
- ALB tích hợp xác thực với Cognito.
Listener rules for your Application Load Balancer
When a system splits into several services, one load balancer can still front them all and send each request to the right service by path or domain name.
MFTECH splits its system into an orders service, a products service and promotional microsites, each with its own target group. They all still sit behind one ALB. Each request goes through the HTTPS listener: certificate selection (SNI), AWS WAF, then the listener rule whose conditions (path, host) match performs the rule’s actions: authentication (if there is an authenticate action), then forward to a target group. Pick a scenario and send a request:
Nhấn Gửi request để quan sát từng bước xử lý.
Besides path and host, listener rules have four more condition types: http-header, http-request-method, query-string and source-ip (in CIDR form). Each rule has a priority; the ALB evaluates rules from the lowest priority value to the highest, stops at the first rule whose conditions all match, and always evaluates the default rule last. An action can be forward, redirect (301 or 302; HTTP to HTTPS is allowed, HTTPS to HTTP is not), fixed-response (returns a 2XX, 4XX or 5XX code at the ALB) or authenticate. Pick a request and see which rule handles it:
(mọi request còn lại)redirect 301 → HTTPS :443source-ip: 203.0.113.0/24path-pattern: /admin/*forward → TG adminpath-pattern: /admin/*fixed-response 403http-header: X-App-Platform: mobileforward → TG mobile-apiquery-string: version=betaforward → TG products-betahttp-request-method: POSTpath-pattern: /orders/*forward → TG orders-writepath-pattern: /orders/*forward → TG orderspath-pattern: /products/*forward → TG products(mọi request còn lại)forward → TG webChọn một request, sau đó nhấn Đánh giá rule. ALB xét các rule theo priority từ giá trị nhỏ tới lớn và dừng ở rule đầu tiên khớp mọi điều kiện.
- Listener rules route by path (
/orders/*, the query string is not considered), host (*.mftech.vnmatcheskhuyenmai.mftech.vnbut not the apex domainmftech.vn), header, method, query string and source IP; a rule with a lower priority value is evaluated first. - The HTTP :80 listener uses a redirect action to move clients to HTTPS.
- The ALB has no built-in request rate limiting: associate AWS WAF and use a rate-based rule (counts by source IP by default, evaluation window of 1, 2, 5 or 10 minutes, minimum limit of 10 requests).
- The ALB integrates authentication with Cognito.