-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnginx.conf.template
130 lines (101 loc) · 4.3 KB
/
nginx.conf.template
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
122
123
124
125
126
127
128
129
130
# This file becomes /etc/nginx/conf.d/default.conf
# See template-port-env-subst.sh
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen ${CYBER_DOJO_NGINX_PORT};
server_name localhost;
# Use Docker embedded DNS server at 127.0.0.11 if running locally
# https://stackoverflow.com/questions/35744650/docker-network-nginx-resolver
resolver ${NGINX_RESOLVER_IP};
# Path for static files
root /usr/share/nginx/html;
client_max_body_size 1G;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Home page redirects...
rewrite ^/$ /creator/home permanent;
rewrite ^/dojo/index(.*) /creator/home permanent;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Read-Eval-Print-Loop service (uses web-sockets)
set $repler_hostname ${CYBER_DOJO_REPLER_HOSTNAME};
location /repler/ {
proxy_pass http://$repler_hostname:${CYBER_DOJO_REPLER_PORT}/repl/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# favicon.ico is in images/ dir for tidyness.
location = /favicon.ico {
root /usr/share/nginx/html/images;
}
rewrite ^/assets/favicon-(.*).ico /usr/share/nginx/html/images/favicon.ico permanent;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Microservices
# Set services hostnames to force re-resolution of the DNS names
# https://medium.com/driven-by-code/dynamic-dns-resolution-in-nginx-22133c22e3ab
set $creator_hostname ${CYBER_DOJO_CREATOR_HOSTNAME};
set $saver_hostname ${CYBER_DOJO_SAVER_HOSTNAME};
set $dashboard_hostname ${CYBER_DOJO_DASHBOARD_HOSTNAME};
set $differ_hostname ${CYBER_DOJO_DIFFER_HOSTNAME};
set $custom_start_points_hostname ${CYBER_DOJO_CUSTOM_START_POINTS_HOSTNAME};
set $exercises_start_points_hostname ${CYBER_DOJO_EXERCISES_START_POINTS_HOSTNAME};
set $languages_start_points_hostname ${CYBER_DOJO_LANGUAGES_START_POINTS_HOSTNAME};
set $runner_hostname ${CYBER_DOJO_RUNNER_HOSTNAME};
set $repler_hostname ${CYBER_DOJO_REPLER_HOSTNAME};
set $web_hostname ${CYBER_DOJO_WEB_HOSTNAME};
location /creator/ {
rewrite ^/creator/(.*) /$1 break;
proxy_pass http://$creator_hostname:${CYBER_DOJO_CREATOR_PORT};
}
location /saver/ {
rewrite ^/saver/(.*) /$1 break;
proxy_pass http://$saver_hostname:${CYBER_DOJO_SAVER_PORT};
}
location /dashboard/ {
rewrite ^/dashboard/(.*) /$1 break;
proxy_pass http://$dashboard_hostname:${CYBER_DOJO_DASHBOARD_PORT};
}
location /differ/ {
rewrite ^/differ/(.*) /$1 break;
proxy_pass http://$differ_hostname:${CYBER_DOJO_DIFFER_PORT};
}
location /custom-start-points/ {
rewrite ^/custom-start-points/(.*) /$1 break;
proxy_pass http://$custom_start_points_hostname:${CYBER_DOJO_CUSTOM_START_POINTS_PORT};
}
location /exercises-start-points/ {
rewrite ^/exercises-start-points/(.*) /$1 break;
proxy_pass http://$exercises_start_points_hostname:${CYBER_DOJO_EXERCISES_START_POINTS_PORT};
}
location /languages-start-points/ {
rewrite ^/languages-start-points/(.*) /$1 break;
proxy_pass http://$languages_start_points_hostname:${CYBER_DOJO_LANGUAGES_START_POINTS_PORT};
}
location /repler {
rewrite ^/repler/(.*) /$1 break;
proxy_pass http://$repler_hostname:${CYBER_DOJO_REPLER_PORT};
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# For everything else try a static file, otherwise try web.
location / {
# An HTTP header important enough to have its own Wikipedia entry:
# http://en.wikipedia.org/wiki/X-Forwarded-For
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Help Rack set the proper protocol (eg https) for doing redirects:
proxy_set_header X-Forwarded-Proto $scheme;
# Pass the Host: header from the client right along so redirects
# can be set properly within the Rack application
proxy_set_header Host $http_host;
# We don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
# Try to serve static files from nginx.
if (!-f $request_filename) {
proxy_pass http://$web_hostname:${CYBER_DOJO_WEB_PORT};
break;
}
}
}