Apache implementation of reverse proxy, load balancing and session-keeping configuration

Source: Internet
Author: User
Tags fully qualified domain name

Apache's reverse proxy and load balancing efficiency and configuration process are more troublesome than nginx. In this study Apache load balancing is only to compare the advantages and disadvantages of other software.
The test process is as follows:

To see if the Proxy module is installed:

[Root@localhost ~]# httpd-m | grep Proxy
Httpd:could not reliably determine the server's fully qualified domain name, using Localhost.localdomain for ServerName
Syntax OK
Proxy_module (Shared)
Proxy_balancer_module (Shared)
Proxy_ftp_module (Shared)
Proxy_http_module (Shared)
Proxy_ajp_module (Shared)
Proxy_connect_module (Shared)

To see if the proxy module has been loaded:

[Root@localhost ~]# cat/etc/httpd/conf/httpd.conf | grep Proxy | Grep-v "^#"
LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule Proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule Proxy_http_module modules/mod_proxy_http.so
LoadModule Proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule Proxy_connect_module modules/mod_proxy_connect.so

Edit httpd.conf configuration file, add:

#关闭正向代理
Proxyrequests off

#添加响应头

Header add Set-cookie "routeid=.%{balancer_worker_route}e; path=/"env=balancer_route_changed
#负载均衡
<proxy balancer://cluster1>
Balancermember http://192.168.0.153:80 loadfactor=3 ROUTE=WWW1
Balancermember http://192.168.0.154:80 loadfactor=1 ROUTE=WWW2
Proxyset lbmethod=byrequests Stickysession=routeid
</Proxy>

#对监控页面不传到后端服务器
Proxypass/balancer-manager!

Proxypass/balancer://cluster1/nofailover=on
proxypassreverse/balancer://cluster1/

#设置监控页
<Location/balancer-manager>
SetHandler Balancer-manager
Order Deny,allow
Allow from all
</Location>

Loadfactor Parameters:

The higher the value, the more services the response will be, taking a value between 1 and 100

Lbmethod Parameters:
Lbmethod=byrequests balance by request (default)
Lbmethod=bytraffic according to flow balance
Lbmethod=bybusyness by busy level (always assigned to the server with the least number of active requests)

Session retention Function:

Route= Set Server ID
Stickysession=routeid use server ID for session retention

English manual for Apache, no session-keeping examples in Chinese version:

Http://www.rootop.org/ApacheManual/Apache2.2_en_US/mod/mod_proxy_balancer.html

Restart Apache, test.


You can see that the second image is a load-balanced cookie to access the server to achieve session retention.

Ps:

When you open the page, prompt the server 500 error to view the log:

[Warn] Proxy:no protocol handler is valid for the url/public/js/jquery.js. If you are are using a DSO version of Mod_proxy, make sure the proxy submodules are included in the configuration using LOADMO Dule.
The reason is that there is a slash behind the proxypass/balancer://cluster1/cluster1, not a "Balancer://cluster1″
It's okay to load up on most of the modules on the Web.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.