How do I set up apache virtualhosts proxies to subdomains on different docker containers -
i have project setup multiple docker containers , trying access subdomain trying proxy container. can achieve similar when not sub domain, example following allows me hit localdev.com/api
:
<virtualhost localdev.com:80> servername localdev.com setenv project_home /project/server setenv project_server_id local setenv project_environment docker documentroot /project/server/www <directory /project/server/www> require granted </directory> <proxy *> allow localhost </proxy> proxypass /api http://api.localdev.com/ proxypassreverse /api http://api.localdev.com/ </virtualhost>
but when add virtual host api.localdev.com
forwarded localdev (the url doesn't change in browser content it)
this subdomain virtualhost:
<virtualhost api.localdev.com:80> servername api.localdev.com <proxy *> allow localhost </proxy> proxypass / http://api.localdev.com/ proxypassreverse / http://api.localdev.com/ </virtualhost>
the funny thing in apache logs correct host, i.e. api.localdev.com
, within docker container containing localdev.com
can both ping & curl api.localdev.com
while not relevant issue, on mac host file have following map docker-container
127.0.0.1 localhost localdev.com api.localdev.com
anywhere have looked online try , solve has not been clear , admit find examples confusing. appreciated , happy provide further information if missing anything
i found solution this. instead of creating 2nd virtual host added rewrite rule condition api sub domain:
# proxy api subdomain api container rewritecond %{http_host} ^api\.localdev\.com$ rewriterule (.*) http://api.localdev.com$1 [p]
now seems behave expected.
Comments
Post a Comment