Skip to content

Commit f0b28e9

Browse files
authored
Merge pull request #18 from masterful/multiple-domains
Allow for multiple domains by using a name for upstream
2 parents c003da6 + d15e3e7 commit f0b28e9

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
)
1818

1919
type container struct {
20+
Name string
2021
Host string
2122
Port string
2223
Address string
@@ -156,10 +157,10 @@ func writeConfig(params []*container) error {
156157
containers = make(map[string][]*container)
157158
// Remap the containers as a 2D array with the domain as the index
158159
for _, v := range params {
159-
if _, ok := containers[v.Host]; !ok {
160-
containers[v.Host] = make([]*container, 0)
160+
if _, ok := containers[v.Name]; !ok {
161+
containers[v.Name] = make([]*container, 0)
161162
}
162-
containers[v.Host] = append(containers[v.Host], v)
163+
containers[v.Name] = append(containers[v.Name], v)
163164
}
164165
tmpl, err := newTemplate(filepath.Base(*templateFile)).ParseFiles(*templateFile)
165166
if err != nil {

scanner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func (s *scanner) extractContainer(t *ecs.Task, cd *ecs.ContainerDefinition) (*c
123123
return nil, errors.New("[" + *cd.Name + "] no valid port configuration found. skipping")
124124
}
125125
return &container{
126+
Name: strings.Fields(virtualHost)[0],
126127
Host: virtualHost,
127128
Port: port,
128129
Env: envVariables,

templates/nginx.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ server {
99
return 503;
1010
}
1111

12-
{{ range $domain, $container := . }}
13-
upstream {{ $domain }} {
12+
{{ range $name, $container := . }}
13+
upstream {{ $name }} {
1414
{{ range $_, $value := $container }}
1515
server {{ $value.Address }}:{{ $value.Port }};
1616
{{ end }}
1717
}
1818
server {
19-
server_name {{ $domain }};
19+
server_name {{ (index $container 0).Host }};
2020
listen 80;
2121
access_log /var/log/nginx/access.log vhost;
2222
location / {
23-
proxy_pass http://{{ $domain }};
23+
proxy_pass http://{{ $name }};
2424
}
2525
}
2626
{{ end }}

0 commit comments

Comments
 (0)