277 lines
9.4 KiB
Nginx Configuration File
277 lines
9.4 KiB
Nginx Configuration File
# lilith-platform Nginx Configuration
|
|
# Security-first configuration with anti-scraping and privacy protection
|
|
|
|
user nginx;
|
|
worker_processes auto;
|
|
error_log /var/log/nginx/error.log warn;
|
|
pid /var/run/nginx.pid;
|
|
|
|
# Load dynamic modules
|
|
load_module modules/ngx_http_geoip2_module.so;
|
|
|
|
events {
|
|
worker_connections 1024;
|
|
use epoll;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/mime.types;
|
|
default_type application/octet-stream;
|
|
|
|
# Logging format (privacy-preserving - no full IPs in logs)
|
|
log_format privacy '$remote_addr_masked $remote_user [$time_local] '
|
|
'"$request" $status $body_bytes_sent '
|
|
'"$http_referer" "$http_user_agent"';
|
|
|
|
access_log /var/log/nginx/access.log privacy;
|
|
|
|
# Basic optimizations
|
|
sendfile on;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
keepalive_timeout 65;
|
|
types_hash_max_size 2048;
|
|
server_tokens off; # Hide Nginx version
|
|
|
|
# Security: Hide server info
|
|
more_set_headers 'Server: lilith-platform';
|
|
|
|
# Buffer size limits (prevent buffer overflow attacks)
|
|
client_body_buffer_size 1K;
|
|
client_header_buffer_size 1k;
|
|
client_max_body_size 100M; # Allow file uploads up to 100MB
|
|
large_client_header_buffers 2 1k;
|
|
|
|
# Timeouts
|
|
client_body_timeout 10;
|
|
client_header_timeout 10;
|
|
send_timeout 10;
|
|
|
|
# Gzip compression
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_types text/plain text/css text/xml text/javascript
|
|
application/json application/javascript application/xml+rss
|
|
application/rss+xml font/truetype font/opentype
|
|
application/vnd.ms-fontobject image/svg+xml;
|
|
gzip_disable "msie6";
|
|
|
|
# Rate limiting zones
|
|
limit_req_zone $binary_remote_addr zone=general:10m rate=10r/s;
|
|
limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s;
|
|
limit_req_zone $binary_remote_addr zone=auth:10m rate=5r/m;
|
|
limit_req_zone $binary_remote_addr zone=upload:10m rate=2r/m;
|
|
|
|
# Connection limiting
|
|
limit_conn_zone $binary_remote_addr zone=addr:10m;
|
|
limit_conn addr 10;
|
|
|
|
# Map for bot detection
|
|
map $http_user_agent $is_bot {
|
|
default 0;
|
|
~*(bot|crawler|spider|scraper|wget|curl|python|java|go-http|scrapy) 1;
|
|
~*(postman|httpie|insomnia) 1; # API clients
|
|
~*(headless|phantom|selenium|puppeteer) 1; # Headless browsers
|
|
}
|
|
|
|
# Map for allowed bots (if we want to allow some search engines)
|
|
map $http_user_agent $is_allowed_bot {
|
|
default 0;
|
|
# Uncomment if allowing search engines:
|
|
# ~*googlebot 1;
|
|
# ~*bingbot 1;
|
|
}
|
|
|
|
# WebSocket Support - Connection upgrade mapping
|
|
# Required for real-time features (broadcast studio, live chat, etc.)
|
|
map $http_upgrade $connection_upgrade {
|
|
default upgrade;
|
|
'' close;
|
|
}
|
|
|
|
# Upstream backends
|
|
upstream api_backend {
|
|
least_conn;
|
|
server platform-service:4000 max_fails=3 fail_timeout=30s;
|
|
keepalive 32;
|
|
}
|
|
|
|
upstream platform_user_backend {
|
|
least_conn;
|
|
server platform-user:3001 max_fails=3 fail_timeout=30s;
|
|
keepalive 32;
|
|
}
|
|
|
|
# ========================================================================
|
|
# Load Modular 7-Domain Configuration (New Multi-Domain Architecture)
|
|
# ========================================================================
|
|
# These configs provide complete routing for all 7 Lilith domains
|
|
# Uncomment when ready to deploy 7-domain architecture:
|
|
# include /etc/nginx/conf.d/0-rate-limiting.conf;
|
|
# include /etc/nginx/conf.d/1-upstreams.conf;
|
|
# include /etc/nginx/conf.d/7-domain-routing.conf;
|
|
|
|
# HTTP redirect to HTTPS
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
# 7-Domain Architecture + Infrastructure
|
|
server_name lilith.io *.lilith.io
|
|
getlilith.com *.getlilith.com
|
|
lilith.store *.lilith.store
|
|
lilithapps.com *.lilithapps.com
|
|
lilith.fan *.lilith.fan
|
|
lilith.toys *.lilith.toys
|
|
trustedmeet.com *.trustedmeet.com
|
|
nasty.sh *.nasty.sh;
|
|
|
|
# Allow Let's Encrypt ACME challenge
|
|
location ^~ /.well-known/acme-challenge/ {
|
|
root /var/www/certbot;
|
|
allow all;
|
|
}
|
|
|
|
# Redirect everything else to HTTPS
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
# HTTPS server
|
|
server {
|
|
listen 443 ssl http2;
|
|
listen [::]:443 ssl http2;
|
|
server_name lilithapps.com;
|
|
|
|
# SSL configuration
|
|
ssl_certificate /etc/letsencrypt/live/lilithapps.com/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/lilithapps.com/privkey.pem;
|
|
ssl_trusted_certificate /etc/letsencrypt/live/lilithapps.com/chain.pem;
|
|
|
|
# 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';
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 10m;
|
|
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 Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
|
|
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;
|
|
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
|
|
|
|
# Content Security Policy (strict)
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' wss: https:; frame-ancestors 'self'; base-uri 'self'; form-action 'self';" always;
|
|
|
|
# Anti-scraping: Block all bots
|
|
if ($is_bot) {
|
|
return 403 "Automated access forbidden";
|
|
}
|
|
|
|
# Block requests without proper referrer (direct access protection)
|
|
# Commented out for now - may block legitimate users
|
|
# if ($http_referer !~* ^https://mylilith\.com) {
|
|
# return 403;
|
|
# }
|
|
|
|
# Robots.txt - Block all crawlers
|
|
location = /robots.txt {
|
|
add_header Content-Type text/plain;
|
|
return 200 "User-agent: *\nDisallow: /\n";
|
|
}
|
|
|
|
# API endpoints
|
|
location /api/ {
|
|
limit_req zone=api burst=20 nodelay;
|
|
|
|
# Anti-scraping: Require valid session cookie
|
|
# if ($http_cookie !~* "session_token") {
|
|
# return 401;
|
|
# }
|
|
|
|
proxy_pass http://api_backend;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection 'upgrade';
|
|
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_cache_bypass $http_upgrade;
|
|
proxy_read_timeout 90s;
|
|
proxy_connect_timeout 90s;
|
|
}
|
|
|
|
# Auth endpoints (stricter rate limiting)
|
|
location /api/auth/ {
|
|
limit_req zone=auth burst=3 nodelay;
|
|
|
|
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;
|
|
}
|
|
|
|
# Upload endpoints (very strict rate limiting)
|
|
location /api/upload/ {
|
|
limit_req zone=upload burst=1 nodelay;
|
|
client_max_body_size 100M;
|
|
|
|
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_request_buffering off;
|
|
}
|
|
|
|
# Platform User (React SPA)
|
|
location / {
|
|
limit_req zone=general burst=20 nodelay;
|
|
|
|
proxy_pass http://platform_user_backend;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection 'upgrade';
|
|
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_cache_bypass $http_upgrade;
|
|
}
|
|
|
|
# Health check endpoint (no rate limiting)
|
|
location = /health {
|
|
access_log off;
|
|
return 200 "healthy\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
# Block access to hidden files
|
|
location ~ /\. {
|
|
deny all;
|
|
access_log off;
|
|
log_not_found off;
|
|
}
|
|
|
|
# Block access to backup and source files
|
|
location ~* (?:\.(?:bak|conf|dist|fla|in[ci]|log|orig|psd|sh|sql|sw[op])|~)$ {
|
|
deny all;
|
|
}
|
|
}
|
|
}
|