forked from mtusi2026/mtusi2026lab7
38 lines
1.6 KiB
Nginx Configuration File
38 lines
1.6 KiB
Nginx Configuration File
events { worker_connections 1024; }
|
|
http {
|
|
limit_req_zone $binary_remote_addr zone=login:10m rate=2r/s;
|
|
map $uri $login_key { default ""; /api/v1/auth/sessions $binary_remote_addr; }
|
|
limit_req_zone $login_key zone=login_only:10m rate=2r/s;
|
|
upstream api_backend {
|
|
server api1:8443 max_fails=1 fail_timeout=2s;
|
|
server api2:8443 max_fails=1 fail_timeout=2s;
|
|
}
|
|
server {
|
|
listen 8443 ssl;
|
|
ssl_certificate /tls/ingress/cert.crt;
|
|
ssl_certificate_key /tls/ingress/cert.key;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
client_max_body_size 10m;
|
|
error_page 429 = @limited;
|
|
location @limited { add_header Retry-After 1 always; default_type application/json; return 429 '{"error":{"code":"rate_limited","message":"Too many requests","request_id":"$request_id"}}'; }
|
|
location / {
|
|
limit_req zone=login_only burst=10 nodelay;
|
|
limit_req_status 429;
|
|
proxy_pass https://api_backend;
|
|
proxy_ssl_certificate /tls/lb/cert.crt;
|
|
proxy_ssl_certificate_key /tls/lb/cert.key;
|
|
proxy_ssl_trusted_certificate /tls/ca.crt;
|
|
proxy_ssl_verify on;
|
|
proxy_ssl_server_name on;
|
|
proxy_ssl_name api.internal;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_connect_timeout 1s;
|
|
proxy_read_timeout 15s;
|
|
proxy_next_upstream error timeout http_502 http_503 http_504;
|
|
proxy_next_upstream_tries 2;
|
|
}
|
|
}
|
|
}
|