forked from mtusi2026/mtusi2026lab3
на 5
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
FROM haproxy:3.2-alpine@sha256:dfba86f031bd4c9039f10f8cc5de75991d1b6766d5460f0335b980408503baad
|
||||
|
||||
COPY infrastructure/haproxy/haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
|
||||
|
||||
USER haproxy
|
||||
|
||||
EXPOSE 8080
|
||||
@@ -0,0 +1,66 @@
|
||||
global
|
||||
log stdout format raw local0
|
||||
maxconn 2048
|
||||
|
||||
defaults
|
||||
log global
|
||||
mode http
|
||||
option httplog
|
||||
timeout connect 1s
|
||||
timeout client 30s
|
||||
timeout server 30s
|
||||
|
||||
resolvers docker
|
||||
nameserver dns 127.0.0.11:53
|
||||
resolve_retries 3
|
||||
timeout resolve 1s
|
||||
timeout retry 1s
|
||||
hold valid 1s
|
||||
hold other 1s
|
||||
hold refused 1s
|
||||
hold nx 1s
|
||||
hold timeout 1s
|
||||
hold obsolete 1s
|
||||
|
||||
frontend public
|
||||
bind :8080
|
||||
|
||||
acl api_request path_beg /api/ /web-api/ /health/
|
||||
acl web_api path_beg /web-api/
|
||||
acl has_session req.cook(mtusi_session) -m found
|
||||
acl message_create method POST
|
||||
acl message_path path_reg ^/(api|web-api)/v1/chats/[^/]+/messages$
|
||||
|
||||
http-request del-header Authorization if web_api
|
||||
http-request set-header Authorization "Bearer %[req.cook(mtusi_session)]" if web_api has_session
|
||||
http-request del-header Cookie if api_request
|
||||
http-request replace-path ^/web-api/(.*)$ /api/\1 if web_api
|
||||
|
||||
use_backend message_backend if message_create message_path
|
||||
use_backend api_backend if api_request
|
||||
default_backend frontend_backend
|
||||
|
||||
backend api_backend
|
||||
balance leastconn
|
||||
option httpchk
|
||||
http-check send meth GET uri /health/ready ver HTTP/1.1 hdr Host api
|
||||
http-check expect status 200
|
||||
default-server check inter 1s fastinter 500ms downinter 1s fall 2 rise 2 resolvers docker init-addr libc,none
|
||||
server-template api 8 api:8080
|
||||
|
||||
backend message_backend
|
||||
balance leastconn
|
||||
option httpchk
|
||||
option redispatch
|
||||
option http-buffer-request
|
||||
retries 3
|
||||
retry-on conn-failure empty-response response-timeout 502 503 504
|
||||
http-check send meth GET uri /health/ready ver HTTP/1.1 hdr Host api
|
||||
http-check expect status 200
|
||||
default-server check inter 1s fastinter 500ms downinter 1s fall 2 rise 2 resolvers docker init-addr libc,none
|
||||
server-template api 8 api:8080
|
||||
|
||||
backend frontend_backend
|
||||
option httpchk GET /
|
||||
http-check expect status 200
|
||||
server frontend frontend:8080 check inter 2s fall 2 rise 2 resolvers docker init-addr libc,none
|
||||
@@ -1,24 +1,12 @@
|
||||
worker_processes auto;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
worker_connections 512;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
resolver 127.0.0.11 valid=1s ipv6=off;
|
||||
|
||||
map $cookie_mtusi_session $web_authorization {
|
||||
default "Bearer $cookie_mtusi_session";
|
||||
"" "";
|
||||
}
|
||||
|
||||
upstream api_backend {
|
||||
zone api_backend 64k;
|
||||
least_conn;
|
||||
server api:8080 resolve max_fails=2 fail_timeout=2s;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
@@ -31,90 +19,6 @@ http {
|
||||
add_header X-Frame-Options "DENY" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; img-src 'self' data:; style-src 'self'; script-src 'self'; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'" always;
|
||||
|
||||
# Message creation carries an Idempotency-Key. It is therefore safe to
|
||||
# retry a POST on another replica when the selected backend is draining.
|
||||
location ~ ^/api/v1/chats/[^/]+/messages$ {
|
||||
proxy_pass http://api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Cookie "";
|
||||
proxy_connect_timeout 1s;
|
||||
proxy_send_timeout 20s;
|
||||
proxy_read_timeout 20s;
|
||||
proxy_next_upstream error timeout http_502 http_503 http_504 non_idempotent;
|
||||
proxy_next_upstream_tries 3;
|
||||
}
|
||||
|
||||
location ~ ^/web-api/v1/chats/[^/]+/messages$ {
|
||||
rewrite ^/web-api/(.*)$ /api/$1 break;
|
||||
proxy_pass http://api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Authorization $web_authorization;
|
||||
proxy_set_header Cookie "";
|
||||
proxy_connect_timeout 1s;
|
||||
proxy_send_timeout 20s;
|
||||
proxy_read_timeout 20s;
|
||||
proxy_next_upstream error timeout http_502 http_503 http_504 non_idempotent;
|
||||
proxy_next_upstream_tries 3;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Cookie "";
|
||||
proxy_connect_timeout 1s;
|
||||
proxy_send_timeout 20s;
|
||||
proxy_read_timeout 20s;
|
||||
proxy_next_upstream error timeout http_502 http_503 http_504;
|
||||
proxy_next_upstream_tries 2;
|
||||
}
|
||||
|
||||
location /web-api/ {
|
||||
rewrite ^/web-api/(.*)$ /api/$1 break;
|
||||
proxy_pass http://api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Authorization $web_authorization;
|
||||
proxy_set_header Cookie "";
|
||||
proxy_connect_timeout 1s;
|
||||
proxy_send_timeout 20s;
|
||||
proxy_read_timeout 20s;
|
||||
proxy_next_upstream error timeout http_502 http_503 http_504;
|
||||
proxy_next_upstream_tries 2;
|
||||
}
|
||||
|
||||
location /health/ {
|
||||
proxy_pass http://api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Connection "";
|
||||
proxy_connect_timeout 1s;
|
||||
proxy_read_timeout 5s;
|
||||
proxy_next_upstream error timeout http_502 http_503 http_504;
|
||||
proxy_next_upstream_tries 2;
|
||||
}
|
||||
|
||||
location /assets/ {
|
||||
try_files $uri =404;
|
||||
expires 1y;
|
||||
|
||||
Reference in New Issue
Block a user