From d79fcbf4476fb48d430ad95e10002b51717be752 Mon Sep 17 00:00:00 2001 From: kolbii <47610371+kolbii@users.noreply.github.com> Date: Mon, 11 Mar 2019 04:52:09 +0100 Subject: [PATCH] This commit resolves #98 so custom location can forward to custom path. (#99) Awesome work! --- src/backend/internal/nginx.js | 11 ++++++++++- src/backend/schema/endpoints/proxy-hosts.json | 3 +++ src/backend/templates/_location.conf | 2 +- src/frontend/js/app/nginx/proxy/location-item.ejs | 1 + src/frontend/js/i18n/messages.json | 3 ++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/backend/internal/nginx.js b/src/backend/internal/nginx.js index 89c43a54..faaf77fb 100644 --- a/src/backend/internal/nginx.js +++ b/src/backend/internal/nginx.js @@ -151,7 +151,16 @@ const internalNginx = { const locationRendering = async () => { for (let i = 0; i < host.locations.length; i++) { - renderedLocations += await renderer.parseAndRender(template, host.locations[i]); + let locationCopy = Object.assign({}, host.locations[i]); + + if (locationCopy.forward_host.indexOf('/') > -1) { + const splitted = locationCopy.forward_host.split('/'); + + locationCopy.forward_host = splitted.shift(); + locationCopy.forward_path = `/${splitted.join('/')}`; + } + + renderedLocations += await renderer.parseAndRender(template, locationCopy); } } diff --git a/src/backend/schema/endpoints/proxy-hosts.json b/src/backend/schema/endpoints/proxy-hosts.json index cd98355f..af87c467 100644 --- a/src/backend/schema/endpoints/proxy-hosts.json +++ b/src/backend/schema/endpoints/proxy-hosts.json @@ -99,6 +99,9 @@ "forward_port": { "$ref": "#/definitions/forward_port" }, + "forward_path": { + "type": "string" + }, "advanced_config": { "type": "string" } diff --git a/src/backend/templates/_location.conf b/src/backend/templates/_location.conf index 4a1ca91b..0b8894d1 100644 --- a/src/backend/templates/_location.conf +++ b/src/backend/templates/_location.conf @@ -3,7 +3,7 @@ proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; - proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}; + proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }}; {{ advanced_config }} } diff --git a/src/frontend/js/app/nginx/proxy/location-item.ejs b/src/frontend/js/app/nginx/proxy/location-item.ejs index 66e97c4c..d6f362a0 100644 --- a/src/frontend/js/app/nginx/proxy/location-item.ejs +++ b/src/frontend/js/app/nginx/proxy/location-item.ejs @@ -39,6 +39,7 @@
+ <%- i18n('proxy-hosts', 'cutom-forward-host-help') %>
diff --git a/src/frontend/js/i18n/messages.json b/src/frontend/js/i18n/messages.json index c2da571e..a51f27c6 100644 --- a/src/frontend/js/i18n/messages.json +++ b/src/frontend/js/i18n/messages.json @@ -114,7 +114,8 @@ "help-content": "A Proxy Host is the incoming endpoint for a web service that you want to forward.\nIt provides optional SSL termination for your service that might not have SSL support built in.\nProxy Hosts are the most common use for the Nginx Proxy Manager.", "access-list": "Access List", "allow-websocket-upgrade": "Websockets Support", - "ignore-invalid-upstream-ssl": "Ignore Invalid SSL" + "ignore-invalid-upstream-ssl": "Ignore Invalid SSL", + "cutom-forward-host-help": "Use 1.1.1.1/path for sub-folder forwarding" }, "redirection-hosts": { "title": "Redirection Hosts",