From f00fe275ca0414fd9b6a52068dfa28c228a9bdc3 Mon Sep 17 00:00:00 2001 From: xialj Date: Mon, 13 Feb 2023 14:33:09 +0800 Subject: [PATCH] allow domain like 'com.example.com:8080',use external port and nginx programmer manager listen thses ports --- backend/internal/nginx.js | 10 ++++++++++ backend/templates/_listen.conf | 3 +++ backend/templates/proxy_host.conf | 1 + 3 files changed, 14 insertions(+) diff --git a/backend/internal/nginx.js b/backend/internal/nginx.js index 52bdd66d..0021ba35 100644 --- a/backend/internal/nginx.js +++ b/backend/internal/nginx.js @@ -32,6 +32,16 @@ const internalNginx = { return internalNginx.deleteConfig(host_type, host); // Don't throw errors, as the file may not exist at all }) .then(() => { + boolean use_default_port = false; + let listen_ports = []; + _.each(host.domain_names, (domain_name) => { + if ( domain_name.indexOf(":") < 0 ){ + host.use_default_port = true; + }else{ + let listen_port = parseInt(domain_name.substring(domain_name.indexOf(":")+1)); + } + }); + return internalNginx.generateConfig(host_type, host); }) .then(() => { diff --git a/backend/templates/_listen.conf b/backend/templates/_listen.conf index 730f3a7c..26abc126 100644 --- a/backend/templates/_listen.conf +++ b/backend/templates/_listen.conf @@ -12,4 +12,7 @@ #listen [::]:443; {% endif %} {% endif %} +{% for listen_port in listen_ports %} + listen listen_port; +{% endfor %} server_name {{ domain_names | join: " " }}; diff --git a/backend/templates/proxy_host.conf b/backend/templates/proxy_host.conf index ec30cca0..3ce57a7e 100644 --- a/backend/templates/proxy_host.conf +++ b/backend/templates/proxy_host.conf @@ -56,6 +56,7 @@ proxy_http_version 1.1; {% if allow_websocket_upgrade == 1 or allow_websocket_upgrade == true %} proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; + proxy_set_header Host $host:$server_port; proxy_http_version 1.1; {% endif %}