-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnginx.conf
More file actions
104 lines (83 loc) · 3.33 KB
/
nginx.conf
File metadata and controls
104 lines (83 loc) · 3.33 KB
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
worker_processes auto;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_max_body_size 25M;
server_tokens off;
proxy_hide_header X-Powered-By;
# rate limiting
limit_req_zone $binary_remote_addr zone=req_limit_per_sec:10m rate=1r/s;
limit_req_zone $binary_remote_addr zone=req_limit_per_min:10m rate=60r/m;
limit_req_status 429;
# error pages
error_page 429 /custom_429.html;
error_page 502 /custom_502.html;
error_page 404 /custom_404.html;
# Remove the legacy header and add a CSP header for frame-ancestors:
add_header X-Frame-Options SAMEORIGIN always;
add_header X-Content-Type-Options nosniff always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
# Custom error pages
error_page 502 /custom_502.html;
server {
listen 8080;
# ---- Frontend Remember ----
location / {
alias /app/FrontEnd/remember/;
index index.html;
try_files $uri $uri/ /index.html;
}
location /status {
# Rate limiting for all requests
limit_req zone=req_limit_per_sec nodelay;
limit_req zone=req_limit_per_min nodelay;
add_header Content-Type application/json;
return 200 '{"status":"online","output":"Welcome to the HamzaYslmn API Service! 🏔️","message":"Or perhaps you\'re looking for the answer to the ultimate question of life, the universe, and everything? 🌌"}';
}
location /space {
default_type text/plain; # veya text/html
add_header Content-Type "text/plain; charset=utf-8" always;
return 200 "🌌";
}
# Proxy to Backend API
location /api/ {
#limit_req zone=req_limit_per_sec burst=1 nodelay;
#limit_req zone=req_limit_per_min burst=60 nodelay;
proxy_pass http://127.0.0.1:8001/api/;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
# Optional: Adjust timeouts for WebSocket
proxy_read_timeout 3600;
proxy_send_timeout 3600;
# Standard proxy headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Custom error page location for rate limiting errors
location = /custom_429.html {
internal;
add_header Content-Type application/json;
return 429 '{"message": "Too Many Requests"}';
}
# Custom error page location for backend 502 errors
location = /custom_502.html {
internal;
add_header Content-Type application/json;
return 502 '{"message": "Bad Gateway"}';
}
# Custom error page location for 404 Not Found errors
location = /custom_404.html {
internal;
add_header Content-Type application/json;
return 404 '{"message": "Not Found"}';
}
}
}