Skip to content

Set proxy_pass from enviroment variable when starting container (nginx) #188

@amlwwalker

Description

@amlwwalker

I need to set the proxy_pass in the template depending on whether an enviroment variable is set.

The problem i am having is I need to access the current $container object to get at the .Env object so I can access the enviroment variables. When you generate the server {} block in your nginx template, you are doing it outside of the loop that accesses the contents of each container, as you just need the host:

proxy_pass http://{{ trim $host }};

If I have an enviroment variable that is set when a container is run called PROXY_PASS, how can I check whether that is set, and if so set the proxy_pass to that, otherwise set it to $host?

I tried the following:

{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
    {{ range $index, $value := $containers }}
        #{{ $value.Env.ALEX }}
    {{ end }}
{{ end }}

Which works, however it prints out as many lines as there are containers (in this case just a comment to test if that works).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions