diff --git a/config/nginx/acupedia.conf b/config/nginx/acupedia.conf new file mode 100644 index 0000000..0da466f --- /dev/null +++ b/config/nginx/acupedia.conf @@ -0,0 +1,158 @@ +# ============================================================================== +# Acupedia Platform — Central Containerized Nginx Gateway Configuration +# File: config/nginx/acupedia.conf +# +# Container Upstreams: +# - Backend API -> backend:8000 +# - Storefront -> store:80 +# - Admin Suite -> admin:80 +# - MinIO S3 -> minio:9000 +# ============================================================================== + +# ------------------------------------------------------------------------------ +# Upstream Definitions (Docker Internal DNS on acupedia-net) +# ------------------------------------------------------------------------------ +upstream backend_api { + server backend:8000; + keepalive 32; +} + +upstream store_app { + server store:80; + keepalive 16; +} + +upstream admin_app { + server admin:80; + keepalive 16; +} + +upstream minio_storage { + server minio:9000; + keepalive 32; +} + +# ============================================================================== +# 1. HTTP to HTTPS Global Redirect (Ports 80 -> 443) +# ============================================================================== +server { + listen 80; + listen [::]:80; + server_name acupedia.in www.acupedia.in api.acupedia.in; + + # Let's Encrypt ACME challenge (used for certbot renewal) + location /.well-known/acme-challenge/ { + root /var/www/certbot; + } + + # Redirect all HTTP requests to HTTPS + location / { + return 301 https://$host$request_uri; + } +} + +# ============================================================================== +# 2. Dedicated API Subdomain (api.acupedia.in) +# ============================================================================== +server { + listen 443 ssl; + listen [::]:443 ssl; + server_name api.acupedia.in; + + # SSL Certificates (Mounted from host /etc/letsencrypt) + ssl_certificate /etc/letsencrypt/live/acupedia.in/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/acupedia.in/privkey.pem; + include /etc/letsencrypt/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; + + client_max_body_size 50M; + + # Common Proxy Headers + 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_connect_timeout 60s; + proxy_send_timeout 120s; + proxy_read_timeout 120s; + + # If opened in a browser from the mobile app, redirect to main storefront + location /cart { + return 301 https://acupedia.in$request_uri; + } + + location /checkout { + return 301 https://acupedia.in$request_uri; + } + + # MinIO S3 Presigned Media Proxy (/accupedia-media/) + location /accupedia-media/ { + proxy_pass http://minio_storage; + proxy_set_header Host $http_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; + } + + # FastAPI Swagger Docs & OpenAPI Schema + location /docs { + proxy_pass http://backend_api/docs; + } + + location /openapi.json { + proxy_pass http://backend_api/openapi.json; + } + + # Route all API traffic to FastAPI Backend on port 8000 + location / { + proxy_pass http://backend_api; + } +} + +# ============================================================================== +# 3. Main Domain: Storefront (/) and Admin Panel (/admin) +# ============================================================================== +server { + listen 443 ssl; + listen [::]:443 ssl; + server_name acupedia.in www.acupedia.in; + + # SSL Certificates (Mounted from host /etc/letsencrypt) + ssl_certificate /etc/letsencrypt/live/acupedia.in/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/acupedia.in/privkey.pem; + include /etc/letsencrypt/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; + + client_max_body_size 50M; + + # Common Proxy Headers + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + 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_connect_timeout 60s; + proxy_send_timeout 120s; + proxy_read_timeout 120s; + + # Admin Panel (/admin) + location /admin { + proxy_pass http://admin_app; + } + + # Backend API access via same-origin (acupedia.in/api/ -> avoids CORS) + location /api/ { + proxy_pass http://backend_api/api/; + } + + # Storefront Customer Web App (/) + location / { + proxy_pass http://store_app; + } +} diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index f1d1a99..2660086 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -97,6 +97,7 @@ services: MINIO_SECRET_KEY: ${MINIO_SECRET_KEY:-minioadmin} MINIO_SECURE: "false" MINIO_BUCKET: ${MINIO_BUCKET_NAME:-accupedia-media} + MEDIA_STORAGE_SECURE: ${MEDIA_STORAGE_SECURE:-true} MEDIA_PRESIGN_ENDPOINT: ${MEDIA_PRESIGN_ENDPOINT:-http://localhost:9000} MEDIA_STORAGE_ACCESS_KEY: ${MINIO_ACCESS_KEY:-minioadmin} MEDIA_STORAGE_SECRET_KEY: ${MINIO_SECRET_KEY:-minioadmin} @@ -159,6 +160,28 @@ services: networks: - acupedia-net + # ============================================================ + # 8. Central Nginx Reverse Proxy (Containerized Gateway) + # ============================================================ + nginx: + image: nginx:alpine + container_name: acupedia-nginx + restart: unless-stopped + depends_on: + - backend + - store + - admin + - minio + ports: + - "${HTTP_PORT:-80}:80" + - "${HTTPS_PORT:-443}:443" + volumes: + - ./config/nginx/acupedia.conf:/etc/nginx/conf.d/default.conf:ro + - /etc/letsencrypt:/etc/letsencrypt:ro + - /var/www/certbot:/var/www/certbot + networks: + - acupedia-net + volumes: acupedia-postgres-data: driver: local