Backend schema and migration modifications for allowing static hosts and locations

This commit is contained in:
Nikolaj Frey 2020-08-14 15:00:22 +10:00 committed by Jamie Curnow
parent f61ab55b52
commit 8de118d875
7 changed files with 85 additions and 16 deletions

View File

@ -69,6 +69,9 @@ exports.up = function (knex/*, Promise*/) {
table.json('domain_names').notNull(); table.json('domain_names').notNull();
table.string('forward_ip').notNull(); table.string('forward_ip').notNull();
table.integer('forward_port').notNull().unsigned(); table.integer('forward_port').notNull().unsigned();
table.string('root_dir').notNull();
table.string('index_file').notNull();
table.integer('static').notNull().unsigned().defaultTo(0);
table.integer('access_list_id').notNull().unsigned().defaultTo(0); table.integer('access_list_id').notNull().unsigned().defaultTo(0);
table.integer('certificate_id').notNull().unsigned().defaultTo(0); table.integer('certificate_id').notNull().unsigned().defaultTo(0);
table.integer('ssl_forced').notNull().unsigned().defaultTo(0); table.integer('ssl_forced').notNull().unsigned().defaultTo(0);

View File

@ -222,6 +222,11 @@
"description": "Should we cache assets", "description": "Should we cache assets",
"example": true, "example": true,
"type": "boolean" "type": "boolean"
},
"static": {
"description": "Should the proxy point to static files",
"example": true,
"type": "boolean"
} }
} }
} }

View File

@ -24,14 +24,22 @@
}, },
"forward_host": { "forward_host": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 0,
"maxLength": 255 "maxLength": 255
}, },
"forward_port": { "forward_port": {
"type": "integer", "type": "integer",
"minimum": 1, "minimum": 0,
"maximum": 65535 "maximum": 65535
}, },
"root_dir": {
"type": "string",
"minLength": 0,
},
"index_file": {
"type": "string",
"minLength": 0,
},
"certificate_id": { "certificate_id": {
"$ref": "../definitions.json#/definitions/certificate_id" "$ref": "../definitions.json#/definitions/certificate_id"
}, },
@ -53,6 +61,9 @@
"caching_enabled": { "caching_enabled": {
"$ref": "../definitions.json#/definitions/caching_enabled" "$ref": "../definitions.json#/definitions/caching_enabled"
}, },
"static": {
"$ref": "../definitions.json#/definitions/static"
},
"allow_websocket_upgrade": { "allow_websocket_upgrade": {
"description": "Allow Websocket Upgrade for all paths", "description": "Allow Websocket Upgrade for all paths",
"example": true, "example": true,
@ -76,10 +87,7 @@
"items": { "items": {
"type": "object", "type": "object",
"required": [ "required": [
"forward_scheme", "forward_scheme"
"forward_host",
"forward_port",
"path"
], ],
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
@ -99,6 +107,15 @@
"forward_port": { "forward_port": {
"$ref": "#/definitions/forward_port" "$ref": "#/definitions/forward_port"
}, },
"root_dir": {
"$ref": "#/definitions/root_dir"
},
"index_file": {
"$ref": "#/definitions/index_file"
},
"static": {
"$ref": "#/definitions/static"
},
"forward_path": { "forward_path": {
"type": "string" "type": "string"
}, },
@ -131,6 +148,12 @@
"forward_port": { "forward_port": {
"$ref": "#/definitions/forward_port" "$ref": "#/definitions/forward_port"
}, },
"root_dir": {
"$ref": "#/definitions/root_dir"
},
"index_file": {
"$ref": "#/definitions/index_file"
},
"certificate_id": { "certificate_id": {
"$ref": "#/definitions/certificate_id" "$ref": "#/definitions/certificate_id"
}, },
@ -152,6 +175,9 @@
"caching_enabled": { "caching_enabled": {
"$ref": "#/definitions/caching_enabled" "$ref": "#/definitions/caching_enabled"
}, },
"static": {
"$ref": "#/definitions/static"
},
"allow_websocket_upgrade": { "allow_websocket_upgrade": {
"$ref": "#/definitions/allow_websocket_upgrade" "$ref": "#/definitions/allow_websocket_upgrade"
}, },
@ -204,9 +230,7 @@
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": [
"domain_names", "domain_names",
"forward_scheme", "forward_scheme"
"forward_host",
"forward_port"
], ],
"properties": { "properties": {
"domain_names": { "domain_names": {
@ -221,6 +245,12 @@
"forward_port": { "forward_port": {
"$ref": "#/definitions/forward_port" "$ref": "#/definitions/forward_port"
}, },
"root_dir": {
"$ref": "#/definitions/root_dir"
},
"index_file": {
"$ref": "#/definitions/index_file"
},
"certificate_id": { "certificate_id": {
"$ref": "#/definitions/certificate_id" "$ref": "#/definitions/certificate_id"
}, },
@ -242,6 +272,9 @@
"caching_enabled": { "caching_enabled": {
"$ref": "#/definitions/caching_enabled" "$ref": "#/definitions/caching_enabled"
}, },
"static": {
"$ref": "#/definitions/static"
},
"allow_websocket_upgrade": { "allow_websocket_upgrade": {
"$ref": "#/definitions/allow_websocket_upgrade" "$ref": "#/definitions/allow_websocket_upgrade"
}, },
@ -294,6 +327,12 @@
"forward_port": { "forward_port": {
"$ref": "#/definitions/forward_port" "$ref": "#/definitions/forward_port"
}, },
"root_dir": {
"$ref": "#/definitions/root_dir"
},
"index_file": {
"$ref": "#/definitions/index_file"
},
"certificate_id": { "certificate_id": {
"$ref": "#/definitions/certificate_id" "$ref": "#/definitions/certificate_id"
}, },
@ -315,6 +354,9 @@
"caching_enabled": { "caching_enabled": {
"$ref": "#/definitions/caching_enabled" "$ref": "#/definitions/caching_enabled"
}, },
"static": {
"$ref": "#/definitions/static"
},
"allow_websocket_upgrade": { "allow_websocket_upgrade": {
"$ref": "#/definitions/allow_websocket_upgrade" "$ref": "#/definitions/allow_websocket_upgrade"
}, },

View File

@ -13,3 +13,8 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
server_name {{ domain_names | join: " " }}; server_name {{ domain_names | join: " " }};
{% if static == 1 or static == true %}
root {{ root_dir }};
index {{ index_file }};
{% endif %}

View File

@ -1,9 +1,16 @@
location {{ path }} { location {{ path }} {
{% if static == 0 or static == false %}
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }}; proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }};
{% else %}
alias {{ root_dir }}/$1;
try_files $uri /{{ index_file }} =200;
{% endif %}
{{ advanced_config }} {{ advanced_config }}
} }

View File

@ -29,6 +29,7 @@ server {
{%- if value == "html" %} {%- if value == "html" %}
root /data/nginx/default_www; root /data/nginx/default_www;
# root /var/www/test2;
location / { location / {
try_files $uri /index.html; try_files $uri /index.html;
} }

View File

@ -52,8 +52,14 @@ server {
proxy_http_version 1.1; proxy_http_version 1.1;
{% endif %} {% endif %}
{% if static == 1 or static == true %}
alias {{ root_dir }}/$1;
try_files $uri /{{index_file}} =200;
{% else %}
# Proxy! # Proxy!
include conf.d/include/proxy.conf; include conf.d/include/proxy.conf;
{% endif %}
} }
{% endif %} {% endif %}