Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple BACKEND by having them space-separated #40

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions etc/nginx/nginx.conf.ctmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ http {
{{ $backend := env "BACKEND" }}
{{ $acme_domain := env "ACME_DOMAIN" }}
{{ $ssl_ready := env "SSL_READY" }}
{{ if service $backend }}
upstream {{ $backend }} {

# loop for each backend
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you not mix tabs and spaces in this file please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, oops. Didn't even notice, relied on atom. :-)

{{ range $b := $backend | split " " }}
{{ if service $b }}
upstream {{ $b }} {
# write the address:port pairs for each healthy backend instance
{{range service $backend }}
{{range service $b }}
server {{.Address}}:{{.Port}};
{{end}}
least_conn;
}{{ end }}
{{ end }}
# end loop for each backend

server {
listen 80;
Expand All @@ -61,14 +66,16 @@ http {
alias /var/www/acme/challenge;
}

{{ if service $backend }}
location = /{{ $backend }} {
return 301 /{{ $backend }}/;
{{ range $b := $backend | split " " }}
{{ if service $b }}
location = /{{ $b }} {
return 301 /{{ $b }}/;
}
location /{{ $backend }} {
proxy_pass http://{{ $backend }};
location /{{ $b }} {
proxy_pass http://{{ $b }};
proxy_redirect off;
}
{{ end }}
{{ end }}
{{ end }}

Expand Down Expand Up @@ -107,15 +114,17 @@ http {
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;

{{ if service $backend }}
location = /{{ $backend }} {
return 301 /{{ $backend }}/;
{{ range $b := $backend | split " " }}
{{ if service $b }}
location = /{{ $b }} {
return 301 /{{ $b }}/;
}

location /{{ $backend }} {
proxy_pass http://{{ $backend }};
location /{{ $b }} {
proxy_pass http://{{ $b }};
proxy_redirect off;
}{{ end }}
{{ end }}
}
{{ end }}
}