mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
- setup-apk-build-service.sh: Docker-based Capacitor build server - apk-builder-nginx.conf: nginx reverse proxy configuration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
167 lines
5.2 KiB
Plaintext
167 lines
5.2 KiB
Plaintext
# APK Build Service - Nginx Configuration
|
|
#
|
|
# Usage:
|
|
# 1. Copy to /etc/nginx/sites-available/apk-builder
|
|
# 2. Update server_name to your domain
|
|
# 3. Update SSL certificate paths (or use certbot)
|
|
# 4. sudo ln -s /etc/nginx/sites-available/apk-builder /etc/nginx/sites-enabled/
|
|
# 5. sudo nginx -t && sudo systemctl reload nginx
|
|
#
|
|
# For Let's Encrypt SSL:
|
|
# sudo certbot --nginx -d apk-builder.yourdomain.com
|
|
#
|
|
|
|
# Rate limiting zone (optional - uncomment to enable)
|
|
# limit_req_zone $binary_remote_addr zone=apk_build_limit:10m rate=5r/m;
|
|
|
|
upstream apk_builder {
|
|
server 127.0.0.1:3000;
|
|
keepalive 32;
|
|
}
|
|
|
|
# Redirect HTTP to HTTPS
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name apk-builder.yourdomain.com;
|
|
|
|
# Let's Encrypt challenge
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/certbot;
|
|
}
|
|
|
|
location / {
|
|
return 301 https://$server_name$request_uri;
|
|
}
|
|
}
|
|
|
|
# HTTPS server
|
|
server {
|
|
listen 443 ssl http2;
|
|
listen [::]:443 ssl http2;
|
|
server_name apk-builder.yourdomain.com;
|
|
|
|
# SSL Configuration
|
|
# Option 1: Let's Encrypt (recommended)
|
|
ssl_certificate /etc/letsencrypt/live/apk-builder.yourdomain.com/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/apk-builder.yourdomain.com/privkey.pem;
|
|
|
|
# Option 2: Self-signed (for testing only)
|
|
# ssl_certificate /etc/nginx/ssl/apk-builder.crt;
|
|
# ssl_certificate_key /etc/nginx/ssl/apk-builder.key;
|
|
|
|
# SSL Security Settings
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_timeout 1d;
|
|
ssl_session_cache shared:SSL:50m;
|
|
ssl_session_tickets off;
|
|
|
|
# OCSP Stapling
|
|
ssl_stapling on;
|
|
ssl_stapling_verify on;
|
|
resolver 8.8.8.8 8.8.4.4 valid=300s;
|
|
resolver_timeout 5s;
|
|
|
|
# Security Headers
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
# Allow large file uploads (for project ZIPs)
|
|
client_max_body_size 100M;
|
|
client_body_timeout 300s;
|
|
client_body_buffer_size 128k;
|
|
|
|
# Logging
|
|
access_log /var/log/nginx/apk-builder.access.log;
|
|
error_log /var/log/nginx/apk-builder.error.log;
|
|
|
|
# Health check endpoint (no auth, fast response)
|
|
location = /health {
|
|
proxy_pass http://apk_builder;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Connection "";
|
|
proxy_connect_timeout 5s;
|
|
proxy_read_timeout 10s;
|
|
}
|
|
|
|
# Build submission endpoint (longer timeouts)
|
|
location = /api/build {
|
|
# Optional rate limiting - uncomment to enable
|
|
# limit_req zone=apk_build_limit burst=2 nodelay;
|
|
# limit_req_status 429;
|
|
|
|
proxy_pass http://apk_builder;
|
|
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 "";
|
|
|
|
# Long timeout for upload processing
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 300s;
|
|
proxy_read_timeout 300s;
|
|
}
|
|
|
|
# Status polling endpoint
|
|
location ~ ^/api/build/[a-f0-9-]+/status$ {
|
|
proxy_pass http://apk_builder;
|
|
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 10s;
|
|
proxy_read_timeout 30s;
|
|
}
|
|
|
|
# APK download endpoint (large response, long timeout)
|
|
location ~ ^/api/build/[a-f0-9-]+/download$ {
|
|
proxy_pass http://apk_builder;
|
|
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 "";
|
|
|
|
# Long timeout for large APK downloads
|
|
proxy_connect_timeout 30s;
|
|
proxy_read_timeout 600s;
|
|
proxy_send_timeout 600s;
|
|
|
|
# Buffering for large files
|
|
proxy_buffering on;
|
|
proxy_buffer_size 128k;
|
|
proxy_buffers 4 256k;
|
|
proxy_busy_buffers_size 256k;
|
|
}
|
|
|
|
# All other API endpoints
|
|
location /api/ {
|
|
proxy_pass http://apk_builder;
|
|
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 30s;
|
|
proxy_read_timeout 60s;
|
|
}
|
|
|
|
# Block all other paths
|
|
location / {
|
|
return 404 '{"error": "Not found"}';
|
|
add_header Content-Type application/json;
|
|
}
|
|
}
|