smartbotic.conf.template 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Smartbotic Nginx Configuration
  2. # This file is managed by Smartbotic installer
  3. # Domain: {{DOMAIN}}
  4. # Rate limiting
  5. limit_req_zone $binary_remote_addr zone=api_limit:10m rate=100r/s;
  6. limit_conn_zone $binary_remote_addr zone=conn_limit:10m;
  7. # Upstream definition
  8. upstream smartbotic_http {
  9. server 127.0.0.1:8090;
  10. keepalive 32;
  11. }
  12. # HTTP -> HTTPS redirect
  13. server {
  14. listen 80;
  15. listen [::]:80;
  16. server_name {{SERVER_NAMES}};
  17. # Let's Encrypt challenge
  18. location /.well-known/acme-challenge/ {
  19. root /var/www/certbot;
  20. }
  21. # Redirect all other traffic to HTTPS
  22. location / {
  23. return 301 https://$host$request_uri;
  24. }
  25. }
  26. # HTTPS server
  27. server {
  28. listen 443 ssl;
  29. listen [::]:443 ssl;
  30. http2 on;
  31. server_name {{SERVER_NAMES}};
  32. # SSL certificates (managed by certbot)
  33. ssl_certificate /etc/letsencrypt/live/{{DOMAIN}}/fullchain.pem;
  34. ssl_certificate_key /etc/letsencrypt/live/{{DOMAIN}}/privkey.pem;
  35. ssl_trusted_certificate /etc/letsencrypt/live/{{DOMAIN}}/chain.pem;
  36. # Modern SSL configuration
  37. ssl_protocols TLSv1.2 TLSv1.3;
  38. 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;
  39. ssl_prefer_server_ciphers off;
  40. ssl_session_timeout 1d;
  41. ssl_session_cache shared:SSL:50m;
  42. ssl_session_tickets off;
  43. # OCSP stapling
  44. ssl_stapling on;
  45. ssl_stapling_verify on;
  46. resolver 1.1.1.1 8.8.8.8 valid=300s;
  47. resolver_timeout 5s;
  48. # Security headers
  49. add_header Strict-Transport-Security "max-age=63072000" always;
  50. add_header X-Frame-Options "SAMEORIGIN" always;
  51. add_header X-Content-Type-Options "nosniff" always;
  52. add_header X-XSS-Protection "1; mode=block" always;
  53. add_header Referrer-Policy "strict-origin-when-cross-origin" always;
  54. # Logging
  55. access_log /var/log/nginx/smartbotic_access.log;
  56. error_log /var/log/nginx/smartbotic_error.log;
  57. # Client settings
  58. client_max_body_size 50M;
  59. client_body_timeout 60s;
  60. client_header_timeout 60s;
  61. # Gzip compression
  62. gzip on;
  63. gzip_vary on;
  64. gzip_proxied any;
  65. gzip_comp_level 6;
  66. gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
  67. # API endpoints
  68. location /api/ {
  69. limit_req zone=api_limit burst=50 nodelay;
  70. limit_conn conn_limit 100;
  71. proxy_pass http://smartbotic_http;
  72. proxy_http_version 1.1;
  73. proxy_set_header Host $host;
  74. proxy_set_header X-Real-IP $remote_addr;
  75. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  76. proxy_set_header X-Forwarded-Proto $scheme;
  77. proxy_set_header Connection "";
  78. proxy_read_timeout 300s;
  79. proxy_send_timeout 300s;
  80. proxy_connect_timeout 60s;
  81. proxy_buffering off;
  82. }
  83. # WebUI static files and SPA fallback
  84. location / {
  85. proxy_pass http://smartbotic_http;
  86. proxy_http_version 1.1;
  87. proxy_set_header Host $host;
  88. proxy_set_header X-Real-IP $remote_addr;
  89. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  90. proxy_set_header X-Forwarded-Proto $scheme;
  91. proxy_set_header Connection "";
  92. # Cache static assets
  93. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  94. proxy_pass http://smartbotic_http;
  95. proxy_cache_valid 200 1d;
  96. add_header Cache-Control "public, max-age=86400";
  97. }
  98. }
  99. # Health check endpoint (no rate limit)
  100. location /health {
  101. proxy_pass http://smartbotic_http/api/v1/health;
  102. proxy_http_version 1.1;
  103. proxy_set_header Host $host;
  104. proxy_set_header Connection "";
  105. }
  106. }