Раздел 6. Guides, Tutorials, and HowTos RU EN Пункт 55. Reverse proxy setup guide In addition to being a "basic" web server, and providing static and dynamic content to end-users, Apache httpd (as well as most other web servers) can also act as a reverse proxy server, also-known-as a "gateway" server. In such scenarios, httpd itself does not generate or host the data, but rather the content is obtained by one or several backend servers, which normally have no direct connection to the external network. As httpd receives a request from a client, the request itself is proxied to one of these backend servers, which then handles the request, generates the content and then sends this content back to httpd, which then generates the actual HTTP response back to the client. There are numerous reasons for such an implementation, but generally the typical rationales are due to security, high-availability, load-balancing and centralized authentication/authorization. It is critical in these implementations that the layout, design and architecture of the backend infrastructure (those servers which actually handle the requests) are insulated and protected from the outside; as far as the client is concerned, the reverse proxy server is the sole source of all content. A typical implementation is below: ![]() Reverse Proxy
Simple reverse proxying
The ProxyPass "/" "http://www.example.com/"
To ensure that and ProxyPass "/" "http://www.example.com/" ProxyPassReverse "/" "http://www.example.com/" Only specific URIs can be proxied, as shown in this example: ProxyPass "/images" "http://www.example.com/" ProxyPassReverse "/images" "http://www.example.com/" In the above, any requests which start with the Clusters and Balancers
As useful as the above is, it still has the deficiencies that should
the (single) backend node go down, or become heavily loaded, that proxying
those requests provides no real advantage. What is needed is the ability
to define a set or group of backend servers which can handle such
requests and for the reverse proxy to load balance and failover among
them. This group is sometimes called a cluster but Apache httpd's
term is a balancer. One defines a balancer by leveraging the
<Proxy balancer://myset> BalancerMember http://www2.example.com:8080 BalancerMember http://www3.example.com:8080 ProxySet lbmethod=bytraffic </Proxy> ProxyPass "/images/" "balancer://myset/" ProxyPassReverse "/images/" "balancer://myset/"
The HintBalancerMembers are also sometimes referred to as workers. Balancer and BalancerMember configuration
You can adjust numerous configuration details of the balancers
and the workers via the various parameters defined in
<Proxy balancer://myset> BalancerMember http://www2.example.com:8080 BalancerMember http://www3.example.com:8080 loadfactor=3 timeout=1 ProxySet lbmethod=bytraffic </Proxy> ProxyPass "/images" "balancer://myset/" ProxyPassReverse "/images" "balancer://myset/" Failover
You can also fine-tune various failover scenarios, detailing which
workers and even which balancers should accessed in such cases. For
example, the below setup implements 2 failover cases: In the first,
<Proxy balancer://myset> BalancerMember http://www2.example.com:8080 BalancerMember http://www3.example.com:8080 loadfactor=3 timeout=1 BalancerMember http://hstandby.example.com:8080 status=+H BalancerMember http://bkup1.example.com:8080 lbset=1 BalancerMember http://bkup2.example.com:8080 lbset=1 ProxySet lbmethod=byrequests </Proxy> ProxyPass "/images/" "balancer://myset/" ProxyPassReverse "/images/" "balancer://myset/"
The magic of this failover setup is setting Balancer Manager
One of the most unique and useful features of Apache httpd's reverse proxy is
the embedded balancer-manager application. Similar to
<Location "/balancer-manager"> SetHandler balancer-manager Require host localhost </Location> WarningDo not enable the balancer-manager until you have secured your server. In particular, ensure that access to the URL is tightly restricted.
When the reverse proxy server is accessed at that url
(eg: ![]() This form allows the devops admin to adjust various parameters, take workers offline, change load balancing methods and add new works. For example, clicking on the balancer itself, you will get the following page: ![]() Whereas clicking on a worker, displays this page: ![]()
To have these changes persist restarts of the reverse proxy, ensure that
Dynamic Health Checks
Before httpd proxies a request to a worker, it can "test" if that worker
is available via setting the BalancerMember status flagsIn the balancer-manager the current state, or status, of a worker is displayed and can be set/reset. The meanings of these statuses are as follows:
|
![]() |