Allow for multiple domains by using a name for upstream #18
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Motivation:
The idea behind this request was to allow multiple domains to route to the same task - (for instance, two spelling variations of a sub-domain). Rather than having two task definitions, it'd be nicer to have a single task definition listen to more than one server name.
Changes needed:
The problem is the best way to specify the above use case in Nginx is by specifying all the applicable server names split by whitespace. However, we also use this field for the upstream name and proxy_pass fields, which do not take more than a single argument...
I had considered using something like the ecsTask.Group string for the name field instead, but I believe that such an approach would be unwise as there may be several container definitions within that grouping that require different server names. By utilizing the first host in the virtualHost variable it allows us to group together only those services that share that virtualHost. I believe it to be far less likely that an individual will have a valid use case for using the same virtualHost within two separate task definitions.
I have also updated the sample nginx.tmpl file - and will be submitting a separate PR against the ecs-nginx-proxy repository with the same changes, linking to this PR for the reasoning.
Regex support:
This also allows for regex domain matching, if desired. You'd want to specify a static domain first so that it gets used for the upstream name, but then the remaining server_names can be a regex pattern (probably in quotes, to be safe).