-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
121 lines (97 loc) · 3.57 KB
/
nginx.conf
File metadata and controls
121 lines (97 loc) · 3.57 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Upstream definitions for load balancing
upstream mapservice {
server 192.168.96.193:3000;
}
upstream bookingservice {
server 192.168.96.193:8081;
server 192.168.96.193:8082;
}
upstream userservice {
server 192.168.96.193:8000;
}
upstream statisticsservice {
server 192.168.96.193:5177;
}
# Cache configuration for different services
proxy_cache_path /var/cache/nginx/bookingservice levels=1:2 keys_zone=bookingservice_cache:10m max_size=10g inactive=60m use_temp_path=off;
proxy_cache_path /var/cache/nginx/userservice levels=1:2 keys_zone=userservice_cache:10m max_size=10g inactive=60m use_temp_path=off;
proxy_cache_path /var/cache/nginx/mapservice levels=1:2 keys_zone=mapservice_cache:10m max_size=10g inactive=60m use_temp_path=off;
# Rate limiting configuration
limit_req_zone $binary_remote_addr zone=api_rate_limit:10m rate=50r/s;
# Server configuration
server {
listen 80; # Listen on port 80 (HTTP)
server_name 192.168.96.193; # Server name or IP address
location / {
proxy_pass http://statisticsservice; # Pass requests to statisticsservice - this is a websocket connection
proxy_http_version 1.1; # Use HTTP/1.1
proxy_set_header Upgrade $http_upgrade; # Forward the Upgrade header
proxy_set_header Connection "upgrade"; # Keep the connection alive
proxy_set_header Host $host; # Forward the host header
proxy_set_header X-Real-IP $remote_addr; # Forward the real IP of the client
}
location /api/v1/clinics {
proxy_pass http://mapservice;
# Enable caching
proxy_cache mapservice_cache;
proxy_cache_valid 200 10m; # Cache successful responses for 10 minutes
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_cache_lock on;
# Apply rate limiting
limit_req zone=api_rate_limit burst=100 nodelay;
}
location /api/v1/bookings/ {
proxy_pass http://bookingservice;
# Apply rate limiting
limit_req zone=api_rate_limit burst=100 nodelay;
# Timeouts for high-traffic endpoint
proxy_connect_timeout 10s;
proxy_read_timeout 30s;
proxy_send_timeout 20s;
# Enable caching
# proxy_cache bookingservice_cache;
# proxy_cache_valid 200 10m;
# Bypass cache for non-idempotent request methods (POST, PATCH, DELETE)
# set $bypass_cache 0;
# if ($request_method = POST) {
# set $bypass_cache 1;
# }
# if ($request_method = PATCH) {
# set $bypass_cache 1;
# }
# if ($request_method = DELETE) { # Consider adding if using DELETE method
# set $bypass_cache 1;
# }
# proxy_cache_bypass $bypass_cache;
# proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
# proxy_cache_background_update on;
# proxy_cache_lock on;
}
location /api/v1/patients {
proxy_pass http://userservice;
# Apply rate limiting
limit_req zone=api_rate_limit burst=100 nodelay;
# Enable caching
# proxy_cache userservice_cache;
# proxy_cache_valid 200 5s; # Cache successful responses for 1 minutes
# proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
# proxy_cache_background_update on;
# proxy_cache_lock on;
}
location /api/v1/dentists {
proxy_pass http://userservice;
}
location /api/v1/admins {
proxy_pass http://userservice;
}
location /patient {
proxy_pass http://userservice;
}
location /dentist {
proxy_pass http://userservice;
}
location /admin {
proxy_pass http://userservice;
}
}