05_nginx_snippets.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # nginx.conf
  3. cat > /etc/nginx/nginx.conf <<EOF
  4. user www-data www-data;
  5. worker_processes auto;
  6. worker_cpu_affinity auto;
  7. worker_rlimit_nofile 51200;
  8. pid /run/nginx.pid;
  9. error_log /var/log/nginx/error.log crit;
  10. events {
  11. use epoll;
  12. worker_connections 51200;
  13. multi_accept off;
  14. accept_mutex off;
  15. }
  16. http {
  17. include mime.types;
  18. default_type application/octet-stream;
  19. log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
  20. '\$status \$body_bytes_sent "\$http_referer" '
  21. '"\$http_user_agent" "\$http_x_forwarded_for"';
  22. server_names_hash_bucket_size 128;
  23. client_header_buffer_size 32k;
  24. large_client_header_buffers 4 32k;
  25. client_max_body_size 64m;
  26. sendfile on;
  27. sendfile_max_chunk 512k;
  28. tcp_nopush on;
  29. keepalive_timeout 60;
  30. tcp_nodelay on;
  31. fastcgi_connect_timeout 300;
  32. fastcgi_send_timeout 300;
  33. fastcgi_read_timeout 300;
  34. fastcgi_buffer_size 64k;
  35. fastcgi_buffers 4 64k;
  36. fastcgi_busy_buffers_size 128k;
  37. fastcgi_temp_file_write_size 256k;
  38. gzip on;
  39. gzip_min_length 1k;
  40. gzip_buffers 4 16k;
  41. gzip_http_version 1.1;
  42. gzip_comp_level 2;
  43. gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
  44. gzip_vary on;
  45. gzip_proxied expired no-cache no-store private auth;
  46. gzip_disable "MSIE [1-6]\.";
  47. server_tokens off;
  48. access_log off;
  49. include cloudflare/real_ip.conf;
  50. include conf.d/*.conf;
  51. }
  52. EOF
  53. # create snippets dir
  54. mkdir -p /etc/nginx/snippets
  55. mkdir -p /etc/nginx/cloudflare
  56. # cloudflare/real_ip.conf
  57. touch /etc/nginx/cloudflare/real_ip.conf
  58. # cloudflare/enable-cdn.conf
  59. cat > /etc/nginx/cloudflare/enable-cdn.conf <<EOF
  60. ssl_prefer_server_ciphers off;
  61. ssl_session_timeout 1d;
  62. ssl_session_cache shared:MozSSL:10m;
  63. EOF
  64. # snippets/enable-ssl.conf
  65. cat > /etc/nginx/snippets/enable-ssl.conf <<EOF
  66. ssl_protocols TLSv1.2 TLSv1.3;
  67. ssl_ecdh_curve X25519:P-256:P-384;
  68. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:ECDHE+AES128:RSA+AES128:ECDHE+AES256:RSA+AES256';
  69. EOF
  70. # snippets/enable-hsts.conf
  71. cat > /etc/nginx/snippets/enable-hsts.conf <<EOF
  72. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
  73. add_header X-Frame-Options "SAMEORIGIN" always;
  74. add_header X-XSS-Protection "1; mode=block" always;
  75. add_header X-Content-Type-Options "nosniff" always;
  76. add_header Referrer-Policy "no-referrer-when-downgrade" always;
  77. add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
  78. EOF
  79. # reload nginx
  80. systemctl force-reload nginx