-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnginx.conf
More file actions
65 lines (56 loc) · 2.19 KB
/
nginx.conf
File metadata and controls
65 lines (56 loc) · 2.19 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
upstream upstream_app {
server app:3000;
}
server {
listen 80;
location /oauth2/ {
proxy_pass http://oauth2-proxy:4180;
proxy_set_header X-Forwarded-Uri $http_x_forwarded_uri;
}
location = /oauth2/auth {
internal;
proxy_pass http://oauth2-proxy:4180;
proxy_set_header Content-Length "";
proxy_pass_request_body off;
}
location / {
auth_request /oauth2/auth;
# if user is not logged in, then process request anyway (the "=" sign lets the app backend reset the response status code)
error_page 401 403 = @allow_unauthenticated;
# read headers from OAuth2 proxy into variables
auth_request_set $user $upstream_http_x_auth_request_user;
auth_request_set $email $upstream_http_x_auth_request_email;
auth_request_set $groups $upstream_http_x_auth_request_groups;
auth_request_set $auth_cookie $upstream_http_set_cookie;
# tell backend who is logged in
proxy_set_header X-User $user;
proxy_set_header X-Email $email;
proxy_set_header X-Groups $groups;
# set auth cookie for frontend
add_header Set-Cookie $auth_cookie;
proxy_pass http://upstream_app;
}
location @allow_unauthenticated {
# clear auth headers to prevent impersonation/forgery
proxy_set_header X-User '' ;
proxy_set_header X-Email '';
proxy_set_header X-Groups '';
proxy_pass http://upstream_app;
}
}
# example ingress config (replace %APP_PATH% with actual path):
# server {
# listen 80;
# server_name localhost;
# location /%APP_PATH%/ {
# rewrite ^ $request_uri; # get original URI
# rewrite ^/%APP_PATH%/(.*)$ /$1 break; # remove app path
# return 400; #if the second rewrite won't match
# proxy_pass http://localhost:8089$uri; # this way, nginx does not "sanitize" the request path and does not remove the double slashes we need in the backend
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# proxy_set_header X-Forwarded-Host $host;
# proxy_set_header X-Forwarded-Uri /%APP_PATH%;
# proxy_cookie_path / /%APP_PATH%/;
# }
# }