Sousaneitor30000 commited on
Commit
edae018
·
verified ·
1 Parent(s): 42586f8

Create nginx/nginx.conf

Browse files
Files changed (1) hide show
  1. nginx/nginx.conf +203 -0
nginx/nginx.conf ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🛡️ AntiScam AI Pro - Configuración Nginx
2
+ # Proxy reverso con SSL y optimizaciones
3
+
4
+ user nginx;
5
+ worker_processes auto;
6
+ error_log /var/log/nginx/error.log warn;
7
+ pid /var/run/nginx.pid;
8
+
9
+ events {
10
+ worker_connections 1024;
11
+ use epoll;
12
+ multi_accept on;
13
+ }
14
+
15
+ http {
16
+ # Configuraciones básicas
17
+ include /etc/nginx/mime.types;
18
+ default_type application/octet-stream;
19
+
20
+ # Logging
21
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
22
+ '$status $body_bytes_sent "$http_referer" '
23
+ '"$http_user_agent" "$http_x_forwarded_for"';
24
+
25
+ access_log /var/log/nginx/access.log main;
26
+
27
+ # Optimizaciones de rendimiento
28
+ sendfile on;
29
+ tcp_nopush on;
30
+ tcp_nodelay on;
31
+ keepalive_timeout 65;
32
+ types_hash_max_size 2048;
33
+ client_max_body_size 50M;
34
+
35
+ # Gzip compression
36
+ gzip on;
37
+ gzip_vary on;
38
+ gzip_min_length 1024;
39
+ gzip_proxied any;
40
+ gzip_comp_level 6;
41
+ gzip_types
42
+ text/plain
43
+ text/css
44
+ text/xml
45
+ text/javascript
46
+ application/json
47
+ application/javascript
48
+ application/xml+rss
49
+ application/atom+xml
50
+ image/svg+xml;
51
+
52
+ # Rate limiting
53
+ limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
54
+ limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
55
+
56
+ # Security headers
57
+ add_header X-Frame-Options SAMEORIGIN always;
58
+ add_header X-Content-Type-Options nosniff always;
59
+ add_header X-XSS-Protection "1; mode=block" always;
60
+ add_header Referrer-Policy "strict-origin-when-cross-origin" always;
61
+ add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self';" always;
62
+
63
+ # Upstream para AntiScam AI
64
+ upstream antiscam_backend {
65
+ server antiscam-ai:7860 max_fails=3 fail_timeout=30s;
66
+ keepalive 32;
67
+ }
68
+
69
+ # Redirección HTTP a HTTPS
70
+ server {
71
+ listen 80;
72
+ server_name tu-dominio.com www.tu-dominio.com;
73
+
74
+ # Certificados Let's Encrypt (ACME challenge)
75
+ location /.well-known/acme-challenge/ {
76
+ root /var/www/certbot;
77
+ }
78
+
79
+ # Redireccionar todo a HTTPS
80
+ location / {
81
+ return 301 https://$server_name$request_uri;
82
+ }
83
+ }
84
+
85
+ # Servidor HTTPS principal
86
+ server {
87
+ listen 443 ssl http2;
88
+ server_name tu-dominio.com www.tu-dominio.com;
89
+
90
+ # Certificados SSL
91
+ ssl_certificate /etc/nginx/ssl/cert.pem;
92
+ ssl_certificate_key /etc/nginx/ssl/key.pem;
93
+
94
+ # Configuración SSL moderna
95
+ ssl_protocols TLSv1.2 TLSv1.3;
96
+ ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
97
+ ssl_prefer_server_ciphers off;
98
+ ssl_session_cache shared:SSL:10m;
99
+ ssl_session_timeout 10m;
100
+
101
+ # HSTS
102
+ add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
103
+
104
+ # Archivos estáticos con caché
105
+ location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
106
+ expires 1y;
107
+ add_header Cache-Control "public, immutable";
108
+ try_files $uri @backend;
109
+ }
110
+
111
+ # Rate limiting para rutas sensibles
112
+ location ~ ^/(login|register|api) {
113
+ limit_req zone=login burst=10 nodelay;
114
+ proxy_pass http://antiscam_backend;
115
+ proxy_set_header Host $host;
116
+ proxy_set_header X-Real-IP $remote_addr;
117
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
118
+ proxy_set_header X-Forwarded-Proto $scheme;
119
+ }
120
+
121
+ # WebSocket support para Gradio
122
+ location /queue/join {
123
+ proxy_pass http://antiscam_backend;
124
+ proxy_http_version 1.1;
125
+ proxy_set_header Upgrade $http_upgrade;
126
+ proxy_set_header Connection "upgrade";
127
+ proxy_set_header Host $host;
128
+ proxy_set_header X-Real-IP $remote_addr;
129
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
130
+ proxy_set_header X-Forwarded-Proto $scheme;
131
+ proxy_read_timeout 86400;
132
+ }
133
+
134
+ # Ruta principal de la aplicación
135
+ location / {
136
+ limit_req zone=api burst=20 nodelay;
137
+
138
+ # Proxy headers
139
+ proxy_pass http://antiscam_backend;
140
+ proxy_set_header Host $host;
141
+ proxy_set_header X-Real-IP $remote_addr;
142
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
143
+ proxy_set_header X-Forwarded-Proto $scheme;
144
+
145
+ # Timeouts
146
+ proxy_connect_timeout 60s;
147
+ proxy_send_timeout 60s;
148
+ proxy_read_timeout 60s;
149
+
150
+ # Buffering
151
+ proxy_buffering on;
152
+ proxy_buffer_size 4k;
153
+ proxy_buffers 8 4k;
154
+ proxy_busy_buffers_size 8k;
155
+ }
156
+
157
+ # Ruta para webhooks de Stripe
158
+ location /webhook/stripe {
159
+ limit_req zone=api burst=5 nodelay;
160
+ proxy_pass http://antiscam_backend/webhook/stripe;
161
+ proxy_set_header Host $host;
162
+ proxy_set_header X-Real-IP $remote_addr;
163
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
164
+ proxy_set_header X-Forwarded-Proto $scheme;
165
+ }
166
+
167
+ # Página de mantenimiento
168
+ location @maintenance {
169
+ root /usr/share/nginx/html;
170
+ try_files /maintenance.html =503;
171
+ }
172
+
173
+ # Error pages personalizadas
174
+ error_page 404 /404.html;
175
+ error_page 500 502 503 504 /50x.html;
176
+
177
+ location = /50x.html {
178
+ root /usr/share/nginx/html;
179
+ }
180
+ }
181
+
182
+ # Servidor de monitoreo (opcional)
183
+ server {
184
+ listen 8080;
185
+ server_name localhost;
186
+
187
+ # Status de Nginx
188
+ location /nginx_status {
189
+ stub_status on;
190
+ access_log off;
191
+ allow 127.0.0.1;
192
+ allow 172.16.0.0/12; # Docker networks
193
+ deny all;
194
+ }
195
+
196
+ # Health check
197
+ location /health {
198
+ access_log off;
199
+ return 200 "healthy\n";
200
+ add_header Content-Type text/plain;
201
+ }
202
+ }
203
+ }