170 lines
5.8 KiB
Plaintext
170 lines
5.8 KiB
Plaintext
server {
|
|
listen 80;
|
|
server_name dociva.io www.dociva.io;
|
|
client_max_body_size 100M;
|
|
|
|
# ACME challenge for Let's Encrypt renewal
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/certbot;
|
|
}
|
|
|
|
# Redirect HTTP to HTTPS
|
|
location / {
|
|
return 308 https://dociva.io$request_uri;
|
|
}
|
|
}
|
|
|
|
# --- Gitea HTTP (ACME + redirect) ---
|
|
server {
|
|
listen 80;
|
|
server_name git.dociva.io;
|
|
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/certbot;
|
|
}
|
|
|
|
location / {
|
|
return 308 https://git.dociva.io$request_uri;
|
|
}
|
|
}
|
|
|
|
# Redirect www to non-www
|
|
server {
|
|
listen 443 ssl;
|
|
http2 on;
|
|
server_name www.dociva.io;
|
|
client_max_body_size 100M;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/dociva.io/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/dociva.io/privkey.pem;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
return 308 https://dociva.io$request_uri;
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl;
|
|
http2 on;
|
|
server_name dociva.io;
|
|
client_max_body_size 100M;
|
|
resolver 127.0.0.11 valid=30s ipv6=off;
|
|
set $backend_upstream backend:5000;
|
|
|
|
# SSL certificates (Let's Encrypt via certbot)
|
|
ssl_certificate /etc/letsencrypt/live/dociva.io/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/dociva.io/privkey.pem;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_prefer_server_ciphers on;
|
|
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
|
|
|
|
# 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 "camera=(), microphone=(), geolocation=()" always;
|
|
add_header X-Canonical-Host "dociva.io" always;
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://pagead2.googlesyndication.com https://www.googletagmanager.com https://www.google-analytics.com https://plausible.io; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: blob: https://pagead2.googlesyndication.com https://www.google-analytics.com; connect-src 'self' https://www.google-analytics.com https://pagead2.googlesyndication.com https://plausible.io; frame-src https://googleads.g.doubleclick.net https://tpc.googlesyndication.com; frame-ancestors 'self'" always;
|
|
|
|
# SEO files — no cache, always fresh
|
|
location ~* ^/(sitemap\.xml|robots\.txt|llms\.txt|humans\.txt)$ {
|
|
root /usr/share/nginx/html;
|
|
expires 1d;
|
|
add_header Cache-Control "public, must-revalidate";
|
|
}
|
|
|
|
# Gzip
|
|
gzip on;
|
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript image/svg+xml;
|
|
gzip_min_length 1000;
|
|
|
|
# Brotli (requires ngx_brotli module — disabled for stock nginx:alpine)
|
|
# brotli on;
|
|
# brotli_comp_level 5;
|
|
# brotli_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
|
|
|
|
# SSE streaming for assistant chat
|
|
location /api/assistant/chat/stream {
|
|
proxy_pass http://$backend_upstream;
|
|
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_http_version 1.1;
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
chunked_transfer_encoding off;
|
|
proxy_read_timeout 300s;
|
|
proxy_send_timeout 300s;
|
|
}
|
|
|
|
# API requests → Flask
|
|
location /api/ {
|
|
proxy_pass http://$backend_upstream;
|
|
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_read_timeout 300s;
|
|
proxy_send_timeout 300s;
|
|
}
|
|
|
|
# Frontend static files
|
|
location / {
|
|
root /usr/share/nginx/html;
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
# Cache static assets
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
}
|
|
|
|
# Health check
|
|
location /health {
|
|
proxy_pass http://$backend_upstream/api/health;
|
|
}
|
|
}
|
|
|
|
# --- Gitea HTTPS reverse proxy ---
|
|
server {
|
|
listen 443 ssl;
|
|
http2 on;
|
|
server_name git.dociva.io;
|
|
|
|
# Temporary fallback so nginx can start before git.dociva.io certificate is issued.
|
|
# After DNS is set and certbot runs, switch these back to /live/git.dociva.io/...
|
|
ssl_certificate /etc/letsencrypt/live/dociva.io/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/dociva.io/privkey.pem;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
client_max_body_size 100M;
|
|
resolver 127.0.0.11 valid=30s ipv6=off;
|
|
|
|
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 Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
location / {
|
|
proxy_pass http://gitea:3000;
|
|
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_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $connection_upgrade;
|
|
}
|
|
}
|
|
|
|
# Used by Gitea (and other WS-enabled apps)
|
|
map $http_upgrade $connection_upgrade {
|
|
default upgrade;
|
|
'' close;
|
|
}
|