Files
core/nginx.conf.sigil

163 lines
5.3 KiB
Plaintext
Raw Normal View History

2025-08-01 10:41:10 +03:00
# Global cache configuration
2025-07-31 18:55:59 +03:00
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=discoursio_cache:10m max_size=1g inactive=60m use_temp_path=off;
2025-08-01 10:41:10 +03:00
# Rate limiting zones
limit_conn_zone $binary_remote_addr zone=addr:10m;
limit_req_zone $binary_remote_addr zone=req_zone:10m rate=20r/s;
2025-08-01 10:41:10 +03:00
# HTTP to HTTPS redirect
2023-10-09 23:47:18 +03:00
server {
2025-07-31 18:55:59 +03:00
listen 80;
server_name {{ $.NOSSL_SERVER_NAME }};
return 301 https://$host$request_uri;
}
2024-12-17 20:14:01 +03:00
2025-08-01 10:41:10 +03:00
# Main HTTPS server
2025-07-31 18:55:59 +03:00
server {
listen 443 ssl http2;
2025-08-01 10:41:10 +03:00
server_name {{ $.SSL_SERVER_NAME }};
2025-07-31 18:55:59 +03:00
2025-08-01 10:41:10 +03:00
# SSL configuration
2025-07-31 18:55:59 +03:00
ssl_certificate {{ $.APP_SSL_PATH }}/server.crt;
ssl_certificate_key {{ $.APP_SSL_PATH }}/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
2025-08-01 10:41:10 +03:00
ssl_prefer_server_ciphers off;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384;
2025-07-31 18:55:59 +03:00
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_session_tickets off;
2025-08-01 10:41:10 +03:00
# Gzip configuration
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/javascript
application/xml+rss
application/json
application/xml
image/svg+xml
font/ttf
font/otf
font/woff
font/woff2;
2025-07-31 18:55:59 +03:00
# Security headers
2025-08-01 10:41:10 +03:00
add_header Strict-Transport-Security "max-age=31536000; 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;
2025-07-31 18:55:59 +03:00
# Logging
access_log /var/log/nginx/{{ $.APP }}-access.log;
error_log /var/log/nginx/{{ $.APP }}-error.log;
2025-08-01 10:41:10 +03:00
# Performance settings
2025-07-31 18:55:59 +03:00
client_max_body_size 100M;
2025-08-01 10:41:10 +03:00
client_header_timeout 60s;
client_body_timeout 60s;
send_timeout 60s;
keepalive_timeout 65s;
keepalive_requests 1000;
# Rate limiting
limit_conn addr 100;
limit_req zone=req_zone burst=20 nodelay;
# Main application proxy
location / {
2025-07-31 18:55:59 +03:00
proxy_pass http://{{ $.APP }}-8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header Host $http_host;
2025-08-01 10:41:10 +03:00
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 X-Forwarded-Port $server_port;
2025-07-31 18:55:59 +03:00
proxy_set_header X-Request-Start $msec;
2025-08-01 10:41:10 +03:00
# Proxy buffering
proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 8 4k;
proxy_busy_buffers_size 8k;
# Cache settings for dynamic content
2025-07-31 18:55:59 +03:00
proxy_cache discoursio_cache;
proxy_cache_revalidate on;
2025-08-01 10:41:10 +03:00
proxy_cache_min_uses 1;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_cache_lock on;
2025-08-01 10:41:10 +03:00
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
}
# GraphQL endpoint with specific settings
location /graphql {
proxy_pass http://{{ $.APP }}-8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
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;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
# Large buffering for GraphQL responses
proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 16 8k;
proxy_busy_buffers_size 16k;
# GraphQL specific timeouts
proxy_read_timeout 300s;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
# Disable caching for GraphQL
proxy_cache off;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
2023-10-09 23:47:18 +03:00
}
2025-08-01 10:41:10 +03:00
# Static assets with aggressive caching
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|otf)$ {
2025-07-31 18:55:59 +03:00
proxy_pass http://{{ $.APP }}-8000;
proxy_set_header Host $http_host;
2025-08-01 10:41:10 +03:00
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;
# Aggressive caching for static assets
expires 1y;
add_header Cache-Control "public, immutable";
add_header Vary "Accept-Encoding";
}
2025-08-01 10:41:10 +03:00
# Include custom nginx configurations
2025-07-31 18:55:59 +03:00
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
2023-10-09 23:47:18 +03:00
}
2023-10-09 23:47:18 +03:00
{{ range $upstream_port := $.PROXY_UPSTREAM_PORTS | split " " }}
upstream {{ $.APP }}-{{ $upstream_port }} {
2025-07-31 18:55:59 +03:00
{{ range $listeners := $.DOKKU_APP_WEB_LISTENERS | split " " }}
{{ $listener_list := $listeners | split ":" }}
{{ $listener_ip := index $listener_list 0 }}
{{ $listener_port := index $listener_list 1 }}
server {{ $listener_ip }}:{{ $upstream_port }};
{{ end }}
}
2024-01-11 19:52:10 +03:00
{{ end }}