mirror of
https://github.com/xiaoxinpro/nginx-proxy-manager-zh.git
synced 2025-02-02 17:58:13 -05:00
better host upstream support
This commit is contained in:
parent
0a50672ab6
commit
ca4d92d793
@ -215,8 +215,6 @@ server {
|
|||||||
|
|
||||||
# default location:
|
# default location:
|
||||||
location / {
|
location / {
|
||||||
proxy_http_version 1.1;
|
|
||||||
|
|
||||||
{{#if Host.AccessListID}}
|
{{#if Host.AccessListID}}
|
||||||
# Authorization
|
# Authorization
|
||||||
auth_basic ""Authorization required"";
|
auth_basic ""Authorization required"";
|
||||||
@ -248,6 +246,7 @@ server {
|
|||||||
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_http_version 1.1;
|
||||||
|
|
||||||
{{#if Upstream.ID}}
|
{{#if Upstream.ID}}
|
||||||
# upstream
|
# upstream
|
||||||
|
@ -87,6 +87,11 @@ func CreateHost() func(http.ResponseWriter, *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if newHost.UpstreamID > 0 {
|
||||||
|
// nolint: errcheck, gosec
|
||||||
|
newHost.Expand([]string{"upstream"})
|
||||||
|
}
|
||||||
|
|
||||||
configureHost(newHost)
|
configureHost(newHost)
|
||||||
|
|
||||||
h.ResultResponseJSON(w, r, http.StatusOK, newHost)
|
h.ResultResponseJSON(w, r, http.StatusOK, newHost)
|
||||||
|
@ -38,6 +38,9 @@ func create(host *Model) (int, error) {
|
|||||||
listen_interface,
|
listen_interface,
|
||||||
domain_names,
|
domain_names,
|
||||||
upstream_id,
|
upstream_id,
|
||||||
|
proxy_scheme,
|
||||||
|
proxy_host,
|
||||||
|
proxy_port,
|
||||||
certificate_id,
|
certificate_id,
|
||||||
access_list_id,
|
access_list_id,
|
||||||
ssl_forced,
|
ssl_forced,
|
||||||
@ -62,6 +65,9 @@ func create(host *Model) (int, error) {
|
|||||||
:listen_interface,
|
:listen_interface,
|
||||||
:domain_names,
|
:domain_names,
|
||||||
:upstream_id,
|
:upstream_id,
|
||||||
|
:proxy_scheme,
|
||||||
|
:proxy_host,
|
||||||
|
:proxy_port,
|
||||||
:certificate_id,
|
:certificate_id,
|
||||||
:access_list_id,
|
:access_list_id,
|
||||||
:ssl_forced,
|
:ssl_forced,
|
||||||
@ -112,6 +118,9 @@ func update(host *Model) error {
|
|||||||
listen_interface = :listen_interface,
|
listen_interface = :listen_interface,
|
||||||
domain_names = :domain_names,
|
domain_names = :domain_names,
|
||||||
upstream_id = :upstream_id,
|
upstream_id = :upstream_id,
|
||||||
|
proxy_scheme = :proxy_scheme,
|
||||||
|
proxy_host = :proxy_host,
|
||||||
|
proxy_port = :proxy_port,
|
||||||
certificate_id = :certificate_id,
|
certificate_id = :certificate_id,
|
||||||
access_list_id = :access_list_id,
|
access_list_id = :access_list_id,
|
||||||
ssl_forced = :ssl_forced,
|
ssl_forced = :ssl_forced,
|
||||||
|
@ -58,7 +58,7 @@ type Model struct {
|
|||||||
Certificate *certificate.Model `json:"certificate,omitempty"`
|
Certificate *certificate.Model `json:"certificate,omitempty"`
|
||||||
NginxTemplate *nginxtemplate.Model `json:"nginx_template,omitempty"`
|
NginxTemplate *nginxtemplate.Model `json:"nginx_template,omitempty"`
|
||||||
User *user.Model `json:"user,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 {
|
func (m *Model) getByQuery(query string, params []interface{}) error {
|
||||||
@ -122,7 +122,7 @@ func (m *Model) Expand(items []string) error {
|
|||||||
if m.UpstreamID > 0 {
|
if m.UpstreamID > 0 {
|
||||||
var u upstream.Model
|
var u upstream.Model
|
||||||
u, err = upstream.GetByID(m.UpstreamID)
|
u, err = upstream.GetByID(m.UpstreamID)
|
||||||
m.Upstream = u
|
m.Upstream = &u
|
||||||
}
|
}
|
||||||
|
|
||||||
if util.SliceContainsItem(items, "user") && m.ID > 0 {
|
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 {
|
if util.SliceContainsItem(items, "upstream") && m.UpstreamID > 0 {
|
||||||
var ups upstream.Model
|
var ups upstream.Model
|
||||||
ups, err = upstream.GetByID(m.UpstreamID)
|
ups, err = upstream.GetByID(m.UpstreamID)
|
||||||
m.Upstream = ups
|
m.Upstream = &ups
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@ -163,6 +163,9 @@ func (m *Model) GetTemplate() Template {
|
|||||||
UserID: m.UserID,
|
UserID: m.UserID,
|
||||||
Type: m.Type,
|
Type: m.Type,
|
||||||
NginxTemplateID: m.NginxTemplateID,
|
NginxTemplateID: m.NginxTemplateID,
|
||||||
|
ProxyScheme: m.ProxyScheme,
|
||||||
|
ProxyHost: m.ProxyHost,
|
||||||
|
ProxyPort: m.ProxyPort,
|
||||||
ListenInterface: m.ListenInterface,
|
ListenInterface: m.ListenInterface,
|
||||||
DomainNames: domainNames,
|
DomainNames: domainNames,
|
||||||
UpstreamID: m.UpstreamID,
|
UpstreamID: m.UpstreamID,
|
||||||
@ -180,7 +183,6 @@ func (m *Model) GetTemplate() Template {
|
|||||||
Status: m.Status,
|
Status: m.Status,
|
||||||
ErrorMessage: m.ErrorMessage,
|
ErrorMessage: m.ErrorMessage,
|
||||||
IsDisabled: m.IsDisabled,
|
IsDisabled: m.IsDisabled,
|
||||||
Upstream: m.Upstream,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return t
|
return t
|
||||||
|
@ -10,6 +10,9 @@ type Template struct {
|
|||||||
UserID int
|
UserID int
|
||||||
Type string
|
Type string
|
||||||
NginxTemplateID int
|
NginxTemplateID int
|
||||||
|
ProxyScheme string
|
||||||
|
ProxyHost string
|
||||||
|
ProxyPort int
|
||||||
ListenInterface string
|
ListenInterface string
|
||||||
DomainNames []string
|
DomainNames []string
|
||||||
UpstreamID int
|
UpstreamID int
|
||||||
|
@ -30,6 +30,11 @@ func ConfigureHost(h host.Model) error {
|
|||||||
certificateTemplate = h.Certificate.GetTemplate()
|
certificateTemplate = h.Certificate.GetTemplate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ups upstream.Model
|
||||||
|
if h.Upstream != nil {
|
||||||
|
ups = *h.Upstream
|
||||||
|
}
|
||||||
|
|
||||||
data := TemplateData{
|
data := TemplateData{
|
||||||
Certificate: certificateTemplate,
|
Certificate: certificateTemplate,
|
||||||
ConfDir: fmt.Sprintf("%s/nginx/hosts", config.Configuration.DataFolder),
|
ConfDir: fmt.Sprintf("%s/nginx/hosts", config.Configuration.DataFolder),
|
||||||
@ -39,7 +44,7 @@ func ConfigureHost(h host.Model) error {
|
|||||||
},
|
},
|
||||||
DataDir: config.Configuration.DataFolder,
|
DataDir: config.Configuration.DataFolder,
|
||||||
Host: h.GetTemplate(),
|
Host: h.GetTemplate(),
|
||||||
Upstream: h.Upstream,
|
Upstream: ups,
|
||||||
}
|
}
|
||||||
|
|
||||||
removeHostFiles(h)
|
removeHostFiles(h)
|
||||||
|
Loading…
Reference in New Issue
Block a user