Skip to content

Commit f575400

Browse files
authored
Merge pull request #1081 from vipergts450/vipergts450-custom_location-patch
Vipergts450 custom location patch
2 parents 6d9a335 + 69ee6b1 commit f575400

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

backend/internal/nginx.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ const internalNginx = {
136136
* @returns {Promise}
137137
*/
138138
renderLocations: (host) => {
139+
140+
//logger.info('host = ' + JSON.stringify(host, null, 2));
139141
return new Promise((resolve, reject) => {
140142
let template;
141143

@@ -146,26 +148,36 @@ const internalNginx = {
146148
return;
147149
}
148150

149-
let renderer = new Liquid();
151+
let renderer = new Liquid({
152+
root: __dirname + '/../templates/'
153+
});
150154
let renderedLocations = '';
151155

152156
const locationRendering = async () => {
153157
for (let i = 0; i < host.locations.length; i++) {
154-
let locationCopy = Object.assign({}, host.locations[i]);
155-
158+
let locationCopy = Object.assign({}, {access_list_id: host.access_list_id}, {certificate_id: host.certificate_id},
159+
{ssl_forced: host.ssl_forced}, {caching_enabled: host.caching_enabled}, {block_exploits: host.block_exploits},
160+
{allow_websocket_upgrade: host.allow_websocket_upgrade}, {http2_support: host.http2_support},
161+
{hsts_enabled: host.hsts_enabled}, {hsts_subdomains: host.hsts_subdomains}, {access_list: host.access_list},
162+
{certificate: host.certificate}, host.locations[i]);
163+
156164
if (locationCopy.forward_host.indexOf('/') > -1) {
157165
const splitted = locationCopy.forward_host.split('/');
158166

159167
locationCopy.forward_host = splitted.shift();
160168
locationCopy.forward_path = `/${splitted.join('/')}`;
161169
}
162170

171+
//logger.info('locationCopy = ' + JSON.stringify(locationCopy, null, 2));
172+
163173
// eslint-disable-next-line
164174
renderedLocations += await renderer.parseAndRender(template, locationCopy);
165175
}
176+
166177
};
167178

168179
locationRendering().then(() => resolve(renderedLocations));
180+
169181
});
170182
},
171183

@@ -181,6 +193,8 @@ const internalNginx = {
181193
logger.info('Generating ' + host_type + ' Config:', host);
182194
}
183195

196+
// logger.info('host = ' + JSON.stringify(host, null, 2));
197+
184198
let renderEngine = new Liquid({
185199
root: __dirname + '/../templates/'
186200
});
@@ -208,6 +222,7 @@ const internalNginx = {
208222
}
209223

210224
if (host.locations) {
225+
//logger.info ('host.locations = ' + JSON.stringify(host.locations, null, 2));
211226
origLocations = [].concat(host.locations);
212227
locationsPromise = internalNginx.renderLocations(host).then((renderedLocations) => {
213228
host.locations = renderedLocations;

backend/templates/_location.conf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,43 @@
33
proxy_set_header X-Forwarded-Scheme $scheme;
44
proxy_set_header X-Forwarded-Proto $scheme;
55
proxy_set_header X-Forwarded-For $remote_addr;
6+
proxy_set_header X-Real-IP $remote_addr;
67
proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }};
8+
9+
{% if access_list_id > 0 %}
10+
{% if access_list.items.length > 0 %}
11+
# Authorization
12+
auth_basic "Authorization required";
13+
auth_basic_user_file /data/access/{{ access_list_id }};
14+
15+
{{ access_list.passauth }}
16+
{% endif %}
17+
18+
# Access Rules
19+
{% for client in access_list.clients %}
20+
{{- client.rule -}};
21+
{% endfor %}deny all;
22+
23+
# Access checks must...
24+
{% if access_list.satisfy %}
25+
{{ access_list.satisfy }};
26+
{% endif %}
27+
28+
{% endif %}
29+
30+
{% include "_assets.conf" %}
31+
{% include "_exploits.conf" %}
32+
33+
{% include "_forced_ssl.conf" %}
34+
{% include "_hsts.conf" %}
35+
36+
{% if allow_websocket_upgrade == 1 or allow_websocket_upgrade == true %}
37+
proxy_set_header Upgrade $http_upgrade;
38+
proxy_set_header Connection $http_connection;
39+
proxy_http_version 1.1;
40+
{% endif %}
41+
42+
743
{{ advanced_config }}
844
}
945

0 commit comments

Comments
 (0)