Skip to content

Conversation

@masterful
Copy link
Contributor

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).

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 the following server_names can be a regex pattern (probably in quotes, to be safe)
@codesuki
Copy link
Owner

Thanks for the pull request! I'll have a look soon.
BTW do you have a specific use case of routing different domains to the same task?

@masterful
Copy link
Contributor Author

The example I mentioned is one use case:
color.example.com and colour.example.com

Another could be if assets are mirrored from a CDN but it passes along the original hostname so you'd have:
app.example.com for the main page and static.example.com for the assets, but the backend can serve both requests...

Another would be optional www:
example.com and www.example.com

Using the regex example you could have:
main.example.com and "~^\w+\.example\.com$"

Does that help at all?

@codesuki
Copy link
Owner

Sure! Makes sense ( ‾ʖ̫‾)
I'll check and merge soon. Thanks again!

@masterful
Copy link
Contributor Author

Just checking in to see if there's anything I ought to be doing for this PR?

@codesuki
Copy link
Owner

Sorry for the late reply! I am gonna merge it today :)

@codesuki codesuki merged commit f0b28e9 into codesuki:master Sep 5, 2017
@codesuki
Copy link
Owner

codesuki commented Sep 5, 2017

Sorry this took so long and for the bad promise! Was super busy and then went on vacation.

Would you mind adding a simple explanation / example to the readme?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants