Trying to understand Yaws
and my docker stack.
I have 3 servers in yaws.conf
: domain.tld
, my.domain.tld
and sm.domain.tld
. These correspond to containers www
, wmy
and wsm
. I want Yaws to process data from domain.tld
via appmod and pass through the other two.
With nginx
as proxy this was not hard to do. How to do it right with Yaws
?
Currently I pass the same appmod to all three and let that appmod decide what to do.
out_check_glue(A) ->
{url, Scheme, Host, _Port , Path, Querypart} = yaws_api:request_url(A),
case Host of
"my.domain.tld" ->
Url = "http://" ++ "wmy" ++ Path ++ get_query(Querypart),
?trace('out_check_glue(A)==++++++++++++++++++++++++++++++++++=========CALL WMY============> Url', [Url]),
vx_request_url(Url);
"sm.domain.tld" ->
Url = "http://" ++ "wsm" ++ Path ++ get_query(Querypart),
?trace('out_check_glue(A)==++++++++++++++++++++++++++++++++++=========CALL WSM============> Url', [Url]),
vx_request_url(Url);
_ ->
?trace('out_check_glue(A)==++++++++++++++++++++++++++++++++++=========NO GLUE============> Scheme, Host,Path,Querypart', [io:format("~n~n~n~p~n", ["WE START HERE out_check_glue"]),Scheme, Host,Path,Querypart]),
out_vx(A)
end.
vx_request_url
just calls httpc:request
with some further discrimination like for container adm
as discussed elsewhere, so I have a simple pass through here, out_vx
starts processing for www
.
This works well. As you see, the appmod can call the appropriate containers directly. This is easily reproduced in the yaws
container as well. Enter the container and issue curl http://wmy
-- voilĂ .
My idea was to not involve the appmod at all as was the case with nginx
and pass this decision on to Yaws
via redirect like so:
# appmods = </, myurl exclude_paths plugins img images styles scripts>
<redirect>
/ = http://wmy
</redirect>
This does not work as intended: not the container is called but the browser which has to error out, of course: there is no domain wmy
to be found.
Why is that so and is there a better solution?
Instead of using a redirect, you can use the Yaws reverse proxy feature, as it will essentially do what your appmod is doing in its "no glue" sections.
For my.domain.tld
and sm.domain.tld
, add a virtual server to your yaws.conf
file, and within each, specify revproxy
:
<server my.domain.tld>
revproxy = / http://wmy
</server>
<server sm.domain.tld>
revproxy = / http://wsm
</server>