-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx_config.conf
68 lines (53 loc) · 1.91 KB
/
nginx_config.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
# Nginx Configuration
# Define events block at the top-level
events {
worker_connections 1024; # adjust as needed
}
# Main http block
http {
# Define an upstream block for load balancing between microservices
# Write your ip addresses for each upstream with ports
upstream auth {
server ; # security-service
}
upstream task {
server ; # task-management-service
}
# Main server block for handling incoming requests
server {
listen 80;
server_name localhost;
location /api/v1/auth/login {
# Direct requests to the security service without authentication check
proxy_pass http://auth/api/v1/auth/login;
}
location /api/v1/auth/register {
# Direct requests to the security service without authentication check
proxy_pass http://auth/api/v1/auth/register;
}
location /api/v1/task {
# Redirect requests to the greeting service
# Authenticate using the security service
auth_request /auth/validate;
# Set X-User-Id header based on the response from /auth/validate
auth_request_set $user_id $upstream_http_x_user_id;
proxy_set_header X-User-Id $user_id;
proxy_pass http://task/api/v1/task;
}
# Authentication endpoint
location = /auth/validate {
internal;
proxy_pass http://auth/api/v1/auth/validate;
proxy_method POST;
proxy_pass_request_body off;
proxy_set_header Host $host;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
# Error handling for failed authentication
error_page 401 = @auth_required;
location @auth_required {
return 401 "Authentication required";
}
}
}