Basic Architecture of Sport Web

This commit is contained in:
Nông Đức Huy
2026-08-11 13:37:25 +07:00
commit 8032fff6ac
262 changed files with 20348 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
# ---------------------------------------------------------------------------
# Edge routing.
#
# In production Cloudflare terminates TLS and sits in front of this; Nginx
# handles routing, buffering, compression and the per-IP rate ceiling. TLS
# config is intentionally absent here because the local stack is plain HTTP.
# ---------------------------------------------------------------------------
upstream storefront_upstream {
server storefront:3000;
keepalive 32;
}
upstream admin_upstream {
server admin:3001;
keepalive 32;
}
upstream api_upstream {
server api:4000;
keepalive 32;
}
# --- Admin dashboard: separate hostname ------------------------------------
# A distinct origin means an XSS on the storefront cannot reach admin cookies,
# and the whole host can be IP-restricted or put behind Cloudflare Access.
server {
listen 80;
server_name admin.localhost;
add_header X-Robots-Tag "noindex, nofollow" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
location /api/ {
limit_req zone=api_limit burst=20 nodelay;
proxy_pass http://api_upstream;
}
location / {
limit_req zone=web_limit burst=40 nodelay;
proxy_pass http://admin_upstream;
}
}
# --- Storefront + public API -----------------------------------------------
server {
listen 80 default_server;
server_name localhost _;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
location /api/ {
limit_req zone=api_limit burst=20 nodelay;
proxy_pass http://api_upstream;
# Payment webhooks and image uploads must not be truncated by a short
# read timeout; everything else here is fast anyway.
proxy_read_timeout 60s;
proxy_buffering off;
}
location = /health {
access_log off;
proxy_pass http://api_upstream/api/v1/health/live;
}
# Next.js build output is content-hashed and therefore immutable.
location /_next/static/ {
proxy_pass http://storefront_upstream;
proxy_cache_valid 200 365d;
add_header Cache-Control "public, max-age=31536000, immutable";
}
location / {
limit_req zone=web_limit burst=40 nodelay;
proxy_pass http://storefront_upstream;
}
}
+73
View File
@@ -0,0 +1,73 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# `request_id` is generated here when the client did not supply one and is
# forwarded to the API, which echoes it back. One id ties the browser's
# network tab, this access log and the application log together.
log_format json_combined escape=json
'{'
'"time":"$time_iso8601",'
'"request_id":"$http_x_request_id",'
'"remote_addr":"$remote_addr",'
'"method":"$request_method",'
'"uri":"$request_uri",'
'"status":$status,'
'"bytes":$body_bytes_sent,'
'"duration":$request_time,'
'"upstream_time":"$upstream_response_time",'
'"referer":"$http_referer",'
'"user_agent":"$http_user_agent"'
'}';
access_log /var/log/nginx/access.log json_combined;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
client_max_body_size 25m;
client_body_timeout 30s;
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_types
application/javascript
application/json
application/xml
image/svg+xml
text/css
text/plain
text/xml;
# Defence in depth. The API rate-limits per actor; this is a blunt
# per-IP ceiling that protects the app tier from ever seeing a flood.
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=30r/s;
limit_req_zone $binary_remote_addr zone=web_limit:10m rate=60r/s;
limit_req_status 429;
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 X-Request-Id $request_id;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
include /etc/nginx/conf.d/*.conf;
}