-
Notifications
You must be signed in to change notification settings - Fork 3
/
nginx.conf
123 lines (106 loc) · 3.85 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
user www;
worker_processes 4; # Ajustado para los 4 núcleos de la Raspberry Pi 3 B+
worker_rlimit_nofile 1024; # Reducido debido a las limitaciones de recursos
load_module /usr/local/libexec/nginx/ngx_http_modsecurity_module.so;
load_module /usr/local/libexec/nginx/ngx_http_brotli_filter_module.so;
load_module /usr/local/libexec/nginx/ngx_http_brotli_static_module.so;
events {
worker_connections 1024; # Reducido para evitar sobrecargar el sistema
use kqueue;
multi_accept on;
}
http {
# General Settings
server_names_hash_bucket_size 64;
server_names_hash_max_size 512;
types_hash_max_size 2048;
client_body_buffer_size 128k; # Reducido
client_max_body_size 10m; # Reducido
client_body_timeout 12s;
client_header_timeout 12s;
keepalive_timeout 15;
send_timeout 10;
keepalive_requests 100;
reset_timedout_connection on;
large_client_header_buffers 4 4k;
# Caché de archivos abiertos
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
server_tokens off;
include mime.types;
default_type application/octet-stream;
# Optimizaciones de rendimiento
sendfile on;
tcp_nopush on;
tcp_nodelay on;
# Caché FastCGI
fastcgi_cache_path /tmp/nginx levels=1:2 keys_zone=WORDPRESS:10m max_size=64m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
# Configuración Brotli
brotli on;
brotli_comp_level 4; # Nivel de compresión reducido
brotli_types text/plain text/css application/json application/javascript application/xml;
# Encabezados de seguridad
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
# Configuración SSL
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:2m;
ssl_session_timeout 1h;
ssl_session_tickets off;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 valid=60s;
resolver_timeout 2s;
# Configuración de IP real
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
# CloudFlare IPs
# List from: https://www.cloudflare.com/ips-v4
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
# List from: https://www.cloudflare.com/ips-v6
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2a06:98c0::/29;
set_real_ip_from 2c0f:f248::/32;
# ModSecurity
modsecurity on;
modsecurity_rules_file /usr/local/etc/modsecurity/modsecurity.conf;
modsecurity_rules_file /usr/local/etc/modsecurity/crs-setup.conf;
modsecurity_rules_file /usr/local/etc/modsecurity/ip_blacklist.conf;
server {
listen 8080;
server_name "";
return 444;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
}
include conf.d/*;
}