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

VIRTUAL_HOST syntax to support multiple destinations #259

Closed
wants to merge 4 commits into from

Conversation

ammmze
Copy link

@ammmze ammmze commented Oct 12, 2015

This request adds some additional functionality to handling the VIRTUAL_HOST environment variable. So in addition to the default functionality (ie VIRUTAL_HOST=www.example.com) you can also do something like this:

- VIRTUAL_HOST=admin.example.com=>https:8444,www.example.com=>http:8080,other.example.com
- VIRTUAL_PORT=8443
- VIRTUAL_PROTO=https

What this ultimately becomes is 3 upstream configurations (admin.example.com, www.example.com, and other.example.com).

  • The admin.example.com upstream would route to https://:8444
  • The www.example.com upstream would route to http://:8080
  • The other.example.com upstream would route to https://:8443
    • It will default to using todays logic if the protocol and port are not specified in the VIRTUAL_HOST syntax

This is useful for scenarios where you have an application that runs multiple interfaces on different ports. (my current use case is the WSO2 API Manager product, which has an admin interface on one port and client endpoints are on a different port). While in production we would probably run a separate instance for the admin (the other part would still be running idle) and a separate instance for the api endpoints and these would be scaled depending on the load. However, in dev environments, we only want the one container and running separate instances is kind of costly given that the WSO2 products each take about 500MB ram to run idle.

@benjamin-smith
Copy link

Would be useful for me. Google AppEngine SDK dev server exposes 2 ports (8080 and 8000). Would love to be able to have 2 upstreams so they can be routed from this Nginx proxy. Right now I can only expose one or the other.

@thomasschmit
Copy link

@jwilder, what's missing to merge this pull request? It'd be very useful!

@TheBlusky
Copy link

Any update on this issue ?
Is it solved ?

@md5
Copy link
Contributor

md5 commented Jan 18, 2016

@TheBlusky No, it is not solved.

@c3s4r
Copy link

c3s4r commented Mar 10, 2016

I'm also needing this feature. @jwilder what's missing for this feature to be integrated? I just took a look on the commits by @bcash-parchment and they look good. What would be the complications? How can I help?

@pascalandy
Copy link

+1

I'm looking to execute this scenario as well:

  • mydomain.com (via a container using a basic nginx svr for static-file (it's the landing page))
  • mydomain.com/blog (via wordpress engine)
  • mydomain.com/stats/ (via a container that monitors the host/static/blog)
  • ... and so one for many utilities :)

Thanks in advance!
Pascal

ammmze added 3 commits June 1, 2016 11:04
…rc virtual hosts. The syntax is used in the VIRTUAL_HOST env variable. Like this VIRTUAL_HOST=www.example.com=>https:8443,admin.example.com=>https:8444
… get the bats working locally in OS X...1) doesn't support -r argument for xargs 2) after hanging for a long time, existing tests gave me:

   -- output differs --
   expected (1 lines):
     answer from port 80 90
   actual (4 lines):
     Command "curl
     --silent
     --fail
     http://172.17.0.32:80 90/data" failed 5 times. Status: 7. Output:

so obviously there is some other stuff in there that doesn't appear to play nice with OS X :(
@ammmze
Copy link
Author

ammmze commented Jun 1, 2016

FYI...I've rebased this on to the current master branch so it is able to merged by someone with authority ;) ... @jwilder

@xloup
Copy link

xloup commented Jun 23, 2016

Thanks @ammmze , I found i can launch the docker with your template using the procedure of launch in separate containers described in the readme, which allows to specify a custom nginx template file

However, to avoid the need of using quotes when setting VIRTUAL_HOST env value for backward compatibility, I changed the separator to "__" from "=>" according to the allowed chars in env variable from this stackoverflow Q/R here
http://stackoverflow.com/questions/2821043/allowed-characters-in-linux-environment-variable-names

@ncadou
Copy link

ncadou commented Jun 30, 2016

You might be interested to know there's a docker image containing this PR: ncadou/nginx-proxy.

Not guaranteed to be kept up to date though.

@ashleysommer
Copy link

@xloup, It looks to me like that rule only applies to Environment Variable Names, not values.
I would say it makes sense to have the variable value wrapped in quotes anyway, so that you can put any string character in there.

@xloup
Copy link

xloup commented Oct 14, 2016

@ashleysommer yes you're right, but for info, at least on my config it breaks backwards compatibility in the sense that if quotes were not obligatory in the past, now they will be. and if this pull request is merged, readme needs to be updated with a note that quotes are obligatory in virtualhost="domain.name" syntax

@ammmze
Copy link
Author

ammmze commented Oct 15, 2016

The quotes should only be required if you use the advanced syntax. You can still use the old syntax without quotes

@Laykou
Copy link

Laykou commented Aug 1, 2017

Can we have this feature please? @jwilder In my case I would like to use this for gitlab-ce docker image where there is GitLab service and Registry both in one docker image but as separate services with separate internal port and externa url domain. This would really help to setup:

VIRTUAL_HOST=gitlab.domain.com=>https:80,registry.domain.com=>https:5000

Or something similiar. I've seen many approaches here. This feature is really wanted 👍

@qnorsten
Copy link

Just wanted to say thank you so much for this PR.
Was looking for this functionality and manually adding it into my custom nginx.tmpl solved the trick.
I wonder why this is not already merged (as I see nothing wrong with it)

@nathanhoel
Copy link

nathanhoel commented Apr 30, 2018

I forked the repo and merged this PR and changed the syntax to '__' instead of '=>' so that it was legal in all env vars.
available on docker hub here https://hub.docker.com/r/nathanhoel/nginx-proxy/
You can see my fork for the source

I was hoping someone had done this... now you don't have to go looking for it like I did!

No guarantees it will stay updated, but if anyone submits update PRs I will merge it and update docker hub!

@anthonyraymond
Copy link

anthonyraymond commented May 30, 2018

👍
Any new on this @jwilder ?

@ammmze can you resolve the conflict, just in case jwilder comes by and want to merge :)

@buchdag buchdag added the type/feat PR for a new feature label Jul 16, 2021
@buchdag buchdag added the scope/multiport Issue or PR related to multi port proxying label Dec 19, 2023
@buchdag buchdag mentioned this pull request May 3, 2024
@buchdag
Copy link
Member

buchdag commented May 9, 2024

Superseded by #2434

@buchdag buchdag closed this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope/multiport Issue or PR related to multi port proxying type/feat PR for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.