10th February 2016
So… You had finally built a nice LXC container for your web-facing application, and even configured Apache (Debian package version 2.14.18-1 in my case) to serve some static/web-only components.
The simplest solution to forward requests from the web-frontend to your API is by using mod_proxy.
If you want to forward any requests to /api/* to your custom back-end server on port 8000, you just add the following lines to your VirtualHost configuration:
ProxyPass “/api” “http://localhost:8000″
ProxyPassReverse “/api” “http://localhost:8000″
I’d suggest not wrapping this fragment with the classical IfModule: as your application will not really work without its API back-end, you actually want Apache to fail as soon as possible if mod_proxy is missing.
That was easy, right? What, it doesn’t work? Can’t be! It’s dead simple! No way you could make a mistake in 2 lines of configuration!!! :mad_rage:
Oh wait… I remember I had this problem before…
- Step 1. Did you disable (using
a2dissite 000-default, depending on your Debian-based GNU/Linux) the default website? If your application and the default website are configured in a similar way, then it might be the default site which is serving your app’s pages. The most sure way is to just disable it.
- Step 2. Did you enable also the proxy_http sub-module? (Using
a2enmod proxy_http, followed by
service apache2 restart) mod_proxy is only the core module, actual per-protocol work is done by these sub-modules.
Your requests to /api should now be passed on to your API server. If not – please write in the comments what was the problem in your case and how you solved it. HTH!