nginx.conf 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # Server globals
  2. user www-data;
  3. worker_processes auto;
  4. worker_rlimit_nofile 65535;
  5. error_log /var/log/nginx/error.log;
  6. pid /run/nginx.pid;
  7. include /etc/nginx/conf.d/main/*.conf;
  8. include /etc/nginx/modules-enabled/*.conf;
  9. # Worker config
  10. events {
  11. worker_connections 1024;
  12. use epoll;
  13. multi_accept on;
  14. }
  15. http {
  16. # Main settings
  17. sendfile on;
  18. tcp_nopush on;
  19. tcp_nodelay on;
  20. client_header_timeout 180s;
  21. client_body_timeout 180s;
  22. client_header_buffer_size 2k;
  23. client_body_buffer_size 256k;
  24. client_max_body_size 1024m;
  25. large_client_header_buffers 4 8k;
  26. send_timeout 60s;
  27. keepalive_timeout 30s;
  28. keepalive_requests 1000;
  29. reset_timedout_connection on;
  30. server_tokens off;
  31. server_name_in_redirect off;
  32. server_names_hash_max_size 512;
  33. server_names_hash_bucket_size 512;
  34. charset utf-8;
  35. # FastCGI settings
  36. fastcgi_buffers 512 4k;
  37. fastcgi_buffer_size 256k;
  38. fastcgi_busy_buffers_size 256k;
  39. fastcgi_temp_file_write_size 256k;
  40. fastcgi_connect_timeout 30s;
  41. fastcgi_read_timeout 300s;
  42. fastcgi_send_timeout 180s;
  43. fastcgi_cache_lock on;
  44. fastcgi_cache_lock_timeout 5s;
  45. fastcgi_cache_background_update on;
  46. fastcgi_cache_revalidate on;
  47. # Proxy settings
  48. proxy_redirect off;
  49. proxy_set_header Host $host;
  50. proxy_set_header Early-Data $rfc_early_data;
  51. proxy_set_header X-Real-IP $remote_addr;
  52. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  53. proxy_pass_header Set-Cookie;
  54. proxy_buffers 256 4k;
  55. proxy_buffer_size 32k;
  56. proxy_busy_buffers_size 32k;
  57. proxy_temp_file_write_size 256k;
  58. proxy_connect_timeout 30s;
  59. proxy_read_timeout 300s;
  60. proxy_send_timeout 180s;
  61. # Log format
  62. log_format main '$remote_addr - $remote_user [$time_local] $request "$status" $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
  63. log_format bytes '$body_bytes_sent';
  64. log_not_found off;
  65. access_log off;
  66. # Mime settings
  67. include /etc/nginx/mime.types;
  68. default_type application/octet-stream;
  69. # Compression
  70. gzip on;
  71. gzip_vary on;
  72. gzip_static on;
  73. gzip_comp_level 6;
  74. gzip_min_length 1024;
  75. gzip_buffers 128 4k;
  76. gzip_http_version 1.1;
  77. gzip_types text/css text/javascript text/js text/plain text/richtext text/shtml text/x-component text/x-java-source text/x-markdown text/x-script text/xml image/bmp image/svg+xml image/vnd.microsoft.icon image/x-icon font/otf font/ttf font/x-woff multipart/bag multipart/mixed application/eot application/font application/font-sfnt application/font-woff application/javascript application/javascript-binast application/json application/ld+json application/manifest+json application/opentype application/otf application/rss+xml application/ttf application/truetype application/vnd.api+json application/vnd.ms-fontobject application/wasm application/xhtml+xml application/xml application/xml+rss application/x-httpd-cgi application/x-javascript application/x-opentype application/x-otf application/x-perl application/x-protobuf application/x-ttf;
  78. gzip_proxied any;
  79. # Cloudflare IPs
  80. include /etc/nginx/conf.d/cloudflare.inc;
  81. # SSL PCI compliance
  82. ssl_buffer_size 1369;
  83. ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA256";
  84. ssl_dhparam /etc/ssl/dhparam.pem;
  85. ssl_early_data on;
  86. ssl_ecdh_curve auto;
  87. ssl_prefer_server_ciphers on;
  88. ssl_protocols TLSv1.2 TLSv1.3;
  89. ssl_session_cache shared:SSL:20m;
  90. ssl_session_tickets on;
  91. ssl_session_timeout 4h;
  92. resolver 1.0.0.1 8.8.4.4 1.1.1.1 8.8.8.8 valid=300s ipv6=off;
  93. resolver_timeout 5s;
  94. # Error pages
  95. error_page 403 /error/404.html;
  96. error_page 404 /error/404.html;
  97. error_page 410 /error/410.html;
  98. error_page 500 501 502 503 504 505 /error/50x.html;
  99. # Proxy cache
  100. proxy_cache_path /var/cache/nginx levels=2 keys_zone=cache:10m inactive=60m max_size=1024m;
  101. proxy_cache_key "$scheme$request_method$host$request_uri";
  102. proxy_temp_path /var/cache/nginx/temp;
  103. proxy_ignore_headers Cache-Control Expires;
  104. proxy_cache_use_stale error timeout invalid_header updating http_502;
  105. proxy_cache_valid any 1d;
  106. # FastCGI cache
  107. fastcgi_cache_path /var/cache/nginx/micro levels=1:2 keys_zone=microcache:10m inactive=30m max_size=1024m;
  108. fastcgi_cache_key "$scheme$request_method$host$request_uri";
  109. fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
  110. fastcgi_cache_use_stale error timeout invalid_header updating http_500 http_503;
  111. add_header X-FastCGI-Cache $upstream_cache_status;
  112. # Cache bypass
  113. map $http_cookie $no_cache {
  114. default 0;
  115. ~SESS 1;
  116. ~wordpress_logged_in 1;
  117. }
  118. # File cache (static assets)
  119. open_file_cache max=10000 inactive=30s;
  120. open_file_cache_valid 60s;
  121. open_file_cache_min_uses 2;
  122. open_file_cache_errors off;
  123. # Wildcard include
  124. include /etc/nginx/conf.d/*.conf;
  125. include /etc/nginx/conf.d/domains/*.conf;
  126. }