Add support for sticky sessions
This commit is contained in:
parent
a86a682429
commit
8bf7007c40
3 changed files with 13 additions and 5 deletions
|
@ -694,6 +694,8 @@ func (lbc *loadBalancerController) getUpstreamServers(data []interface{}) ([]*ng
|
|||
return aUpstreams, aServers
|
||||
}
|
||||
|
||||
// createUpstreams creates the NGINX upstreams for each service referenced in
|
||||
// Ingress rules. The servers inside the upstream are endpoints.
|
||||
func (lbc *loadBalancerController) createUpstreams(data []interface{}) map[string]*nginx.Upstream {
|
||||
upstreams := make(map[string]*nginx.Upstream)
|
||||
|
||||
|
|
|
@ -141,9 +141,13 @@ http {
|
|||
|
||||
{{range $name, $upstream := .upstreams}}
|
||||
upstream {{$upstream.Name}} {
|
||||
{{ if $cfg.enableStickySessions }}
|
||||
sticky hash=sha1 httponly;
|
||||
{{ else }}
|
||||
least_conn;
|
||||
{{range $server := $upstream.Backends}}server {{$server.Address}}:{{$server.Port}};
|
||||
{{end}}
|
||||
{{ end }}
|
||||
{{ range $server := $upstream.Backends }}server {{ $server.Address }}:{{ $server.Port }};
|
||||
{{ end }}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
|
@ -153,9 +157,6 @@ http {
|
|||
{{ if $server.SSL }}listen 443{{ if $cfg.useProxyProtocol }} proxy_protocol{{ end }} ssl http2;
|
||||
ssl_certificate {{ $server.SSLCertificate }};
|
||||
ssl_certificate_key {{ $server.SSLCertificateKey }};{{ end }}
|
||||
{{ if $cfg.enableVtsStatus }}
|
||||
vhost_traffic_status_filter_by_set_key {{ $server.Name }} application::*;
|
||||
{{ end }}
|
||||
|
||||
server_name {{ $server.Name }};
|
||||
|
||||
|
|
|
@ -89,6 +89,11 @@ type nginxConfiguration struct {
|
|||
// Sets the maximum allowed size of the client request body
|
||||
BodySize string `structs:"body-size,omitempty"`
|
||||
|
||||
// EnableStickySessions enabled sticky sessions using cookies
|
||||
// https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng
|
||||
// By default this is disabled
|
||||
EnableStickySessions bool `structs:"enable-sticky-sessions,omitempty"`
|
||||
|
||||
// EnableVtsStatus allows the replacement of the default status page with a third party module named
|
||||
// nginx-module-vts - https://github.com/vozlt/nginx-module-vts
|
||||
// By default this is disabled
|
||||
|
|
Loading…
Reference in a new issue