Add nginx to docker-compose setup

- nginx.conf: docker-compose version (uses 'web:8001')
- nginx-prod.conf: production version (uses '127.0.0.1:8001')
- Separate nginx service in docker-compose
- uvicorn runs on port 8001, nginx exposes 8000

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-30 02:01:00 -05:00
parent a32b79c885
commit d630e629bd
4 changed files with 114 additions and 6 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ COPY . .
RUN python3 -c "from kjvstudy_org.utils.search_index import init_search_index; init_search_index()"
# Copy nginx config and startup script
COPY nginx.conf /etc/nginx/nginx.conf
COPY nginx-prod.conf /etc/nginx/nginx.conf
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh
+14 -3
View File
@@ -1,8 +1,19 @@
services:
web:
build: .
nginx:
image: nginx:alpine
ports:
- "8000:8000"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./kjvstudy_org/static:/app/kjvstudy_org/static:ro
depends_on:
- web
restart: unless-stopped
web:
build: .
expose:
- "8001"
volumes:
- .:/app
- /app/.venv
@@ -11,4 +22,4 @@ services:
- PRELOAD_INTERLINEAR=true
- DISABLE_ANALYTICS=true
restart: unless-stopped
command: uv run uvicorn kjvstudy_org.server:app --host 0.0.0.0 --port 8000 --reload --reload-include '*.json'
command: uv run uvicorn kjvstudy_org.server:app --host 0.0.0.0 --port 8001 --reload --reload-include '*.json'
+97
View File
@@ -0,0 +1,97 @@
worker_processes auto;
error_log /dev/stderr warn;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging
access_log /dev/stdout combined;
# Request buffering - absorb slow clients
client_body_buffer_size 128k;
client_max_body_size 10m;
client_body_timeout 60s;
client_header_timeout 60s;
# Response buffering
proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 8 32k;
proxy_busy_buffers_size 64k;
# Keepalive
keepalive_timeout 65;
keepalive_requests 1000;
# Compression
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
# Upstream - uvicorn (production single container)
upstream app {
server 127.0.0.1:8001;
keepalive 32;
}
server {
listen 8000;
server_name _;
# Static files - serve directly with caching
location /static/ {
alias /app/kjvstudy_org/static/;
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# Service worker - special cache headers
location = /sw.js {
proxy_pass http://app;
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;
add_header Cache-Control "no-cache";
}
# All other requests - proxy to uvicorn
location / {
proxy_pass http://app;
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 "";
# Request buffering
proxy_request_buffering on;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# Health check endpoint - bypass buffering for speed
location = /api/health {
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_buffering off;
}
}
}
+2 -2
View File
@@ -38,9 +38,9 @@ http {
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
# Upstream - uvicorn
# Upstream - uvicorn (use 'web' for docker-compose, '127.0.0.1' for single container)
upstream app {
server 127.0.0.1:8001;
server web:8001;
keepalive 32;
}