Apache can be used as a gateway to backend services by configuring it to act as a reverse proxy server. Requests received by
Apache will be passed to and processed by a backend server or service which the response will then be returned to the
Apache server before finally being passed back to the requesting client.
This allows an
Apache server to listen to a single
IP address or a
DNS name and serve multiple apps and services. This among other things provide centralised control of the backend services while being more secure by not directly exposing the backend servers which are normally hosted in private networks.
Steps to configure Apache as a reverse proxy server:
$ sudo a2enmod proxy_http # Ubuntu and Debian Considering dependency proxy for proxy_http: Enabling module proxy. Enabling module proxy_http.
|Options||apache.org source package||Debian, Ubuntu||Fedora Core, CentOS, RHEL||macOS||Windows||openSUSE and SLES|
|Modules to install||none|
|Module name||proxy, proxy_http|
|Loadmodule directive|| Loadmodule xxx |
<VirtualHost *:80> ProxyRequests Off ProxyPass "/backend-service-01" "http://backend-service-01.local/" ProxyPassReverse "/backend-service-01" "http:///backend-service-01.local" ProxyPass "/backend-service-02" "http://backend-service-02.local/" ProxyPassReverse "/backend-service-02" "http:///backend-service-02.local" </VirtualHost>
$ sudo systemctl restart apache2 # Ubuntu and Debian $ sudo systemctl restart httpd # CentOS and Red Hat
$ curl http://backend-service-01.local I am backend-service-01.local
The request will fail if the backend service is hosted in a private network under a
This test could also be done by browsing the
URL using a web browser.
$ curl http://proxy-server/backend-service-01 I am backend-service-01.local
|Ubuntu 16.04 LTS (Xenial Xerus)|
|Ubuntu 16.10 (Yakkety Yak)|
|Ubuntu 17.04 (Zesty Zapus)|
|Ubuntu 17.10 (Artful Aardvark)|
|Ubuntu 18.04 LTS (Bionic Beaver)|
|Ubuntu 18.10 (Cosmic Cuttlefish)|
|Ubuntu 19.04 (Disco Dingo)|
Comment anonymously. Login not required.