diff --git a/backend/embed/migrations/20201013035839_initial_data.sql b/backend/embed/migrations/20201013035839_initial_data.sql index f1662598..01c43c44 100644 --- a/backend/embed/migrations/20201013035839_initial_data.sql +++ b/backend/embed/migrations/20201013035839_initial_data.sql @@ -215,8 +215,6 @@ server { # default location: location / { - proxy_http_version 1.1; - {{#if Host.AccessListID}} # Authorization auth_basic ""Authorization required""; @@ -248,6 +246,7 @@ server { proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; + proxy_http_version 1.1; {{#if Upstream.ID}} # upstream diff --git a/backend/internal/api/handler/hosts.go b/backend/internal/api/handler/hosts.go index 7154f80f..24ea7365 100644 --- a/backend/internal/api/handler/hosts.go +++ b/backend/internal/api/handler/hosts.go @@ -87,6 +87,11 @@ func CreateHost() func(http.ResponseWriter, *http.Request) { return } + if newHost.UpstreamID > 0 { + // nolint: errcheck, gosec + newHost.Expand([]string{"upstream"}) + } + configureHost(newHost) h.ResultResponseJSON(w, r, http.StatusOK, newHost) diff --git a/backend/internal/entity/host/methods.go b/backend/internal/entity/host/methods.go index 68f00fdc..b40fa018 100644 --- a/backend/internal/entity/host/methods.go +++ b/backend/internal/entity/host/methods.go @@ -38,6 +38,9 @@ func create(host *Model) (int, error) { listen_interface, domain_names, upstream_id, + proxy_scheme, + proxy_host, + proxy_port, certificate_id, access_list_id, ssl_forced, @@ -62,6 +65,9 @@ func create(host *Model) (int, error) { :listen_interface, :domain_names, :upstream_id, + :proxy_scheme, + :proxy_host, + :proxy_port, :certificate_id, :access_list_id, :ssl_forced, @@ -112,6 +118,9 @@ func update(host *Model) error { listen_interface = :listen_interface, domain_names = :domain_names, upstream_id = :upstream_id, + proxy_scheme = :proxy_scheme, + proxy_host = :proxy_host, + proxy_port = :proxy_port, certificate_id = :certificate_id, access_list_id = :access_list_id, ssl_forced = :ssl_forced, diff --git a/backend/internal/entity/host/model.go b/backend/internal/entity/host/model.go index 83d6cee5..5502e0d9 100644 --- a/backend/internal/entity/host/model.go +++ b/backend/internal/entity/host/model.go @@ -58,7 +58,7 @@ type Model struct { Certificate *certificate.Model `json:"certificate,omitempty"` NginxTemplate *nginxtemplate.Model `json:"nginx_template,omitempty"` User *user.Model `json:"user,omitempty"` - Upstream upstream.Model `json:"upstream,omitempty"` + Upstream *upstream.Model `json:"upstream,omitempty"` } func (m *Model) getByQuery(query string, params []interface{}) error { @@ -122,7 +122,7 @@ func (m *Model) Expand(items []string) error { if m.UpstreamID > 0 { var u upstream.Model u, err = upstream.GetByID(m.UpstreamID) - m.Upstream = u + m.Upstream = &u } if util.SliceContainsItem(items, "user") && m.ID > 0 { @@ -146,7 +146,7 @@ func (m *Model) Expand(items []string) error { if util.SliceContainsItem(items, "upstream") && m.UpstreamID > 0 { var ups upstream.Model ups, err = upstream.GetByID(m.UpstreamID) - m.Upstream = ups + m.Upstream = &ups } return err @@ -163,6 +163,9 @@ func (m *Model) GetTemplate() Template { UserID: m.UserID, Type: m.Type, NginxTemplateID: m.NginxTemplateID, + ProxyScheme: m.ProxyScheme, + ProxyHost: m.ProxyHost, + ProxyPort: m.ProxyPort, ListenInterface: m.ListenInterface, DomainNames: domainNames, UpstreamID: m.UpstreamID, @@ -180,7 +183,6 @@ func (m *Model) GetTemplate() Template { Status: m.Status, ErrorMessage: m.ErrorMessage, IsDisabled: m.IsDisabled, - Upstream: m.Upstream, } return t diff --git a/backend/internal/entity/host/template.go b/backend/internal/entity/host/template.go index 4fb54efa..31e133a1 100644 --- a/backend/internal/entity/host/template.go +++ b/backend/internal/entity/host/template.go @@ -10,6 +10,9 @@ type Template struct { UserID int Type string NginxTemplateID int + ProxyScheme string + ProxyHost string + ProxyPort int ListenInterface string DomainNames []string UpstreamID int diff --git a/backend/internal/nginx/control.go b/backend/internal/nginx/control.go index 8fab0e9c..dd79d247 100644 --- a/backend/internal/nginx/control.go +++ b/backend/internal/nginx/control.go @@ -30,6 +30,11 @@ func ConfigureHost(h host.Model) error { certificateTemplate = h.Certificate.GetTemplate() } + var ups upstream.Model + if h.Upstream != nil { + ups = *h.Upstream + } + data := TemplateData{ Certificate: certificateTemplate, ConfDir: fmt.Sprintf("%s/nginx/hosts", config.Configuration.DataFolder), @@ -39,7 +44,7 @@ func ConfigureHost(h host.Model) error { }, DataDir: config.Configuration.DataFolder, Host: h.GetTemplate(), - Upstream: h.Upstream, + Upstream: ups, } removeHostFiles(h)