Using mod_proxy with http/https:

来源:互联网 发布:屏幕录像软件 知乎 编辑:程序博客网 时间:2024/06/04 19:41

This wiki outlines the various steps required to install a basic load-balancing solution based on mod_proxy, mod_proxy_balancer and JBoss. Mod_proxy allows to use http/https and AJP protocols to proxy to JBoss. This documentation is for Apache httpd-2.2.x if you have to use older version of httpd see Load Balancing using mod_rewrite and mod_proxy

 

Using mod_proxy with http/https:

 

Step 1: Download Apache2.2.x Web Server

 

Get the latest Apache2.2.x package from Apache.org and install it. We require no special configuration, just use the default settings. In the following steps, APACHE_HOME will represent the Apache install directory.

 

+

  • Note:* At the time of the writting of this document Apache 2.2.9 is most stable version of Apache httpd-2.2.x and is recommended if you want to use load-balancing using mod_proxy

+

 

 

Step 2: Setup Apache to use mod_proxy (HTTP)

 

 

Make sure that at least following modules are loaded (uncomment this in httpd.conf)

 

     LoadModule proxy_module modules/mod_proxy.so     LoadModule proxy_balancer_module modules/mod_proxy_balancer.so     LoadModule proxy_http_module modules/mod_proxy_http.so

 

These are sufficient for http load balancing. However you may need to load mod_proxy_ftp module if you are using ftp or load mod_proxy_connect module if you are using SSL

 

 

Add those lines in APACHE_HOME/conf/httpd.conf :

 

     <Proxy balancer://mycluster>       Order deny,allow       Allow from all       BalancerMember http://host1:8080 route=node1       BalancerMember http://host2:8180 route=node2     </Proxy>          ProxyPass /jmx-console balancer://mycluster     ProxyPassReverse /jmx-console  http://host1:8080/jmx-console     ProxyPassReverse /jmx-console  http://host2:8180/jmx-console

 

By default the requests are load balanced in byrequests fashion, which performs weighted request counting. This is determined by parameter lbmethod. The stickysession parameter is also required, as there is no default value. stickysession is used to determine which URL session name or cookie to use when looking for the route for the request.

 

     ProxyPass /jmx-console balancer://mycluster lbmethod=byrequests stickysession=JSESSIONID|jsessionid 

 

You can find more about ProxyPass attributes in the Apache HTTP Server documentation at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html .

 

 

Step 3: Configure JBoss Web if you want to use sticky session

 

 

Edit JBOSS_HOME/server/all/deploy/jbossweb-web.deployer/server.xml (replace /all with your own server name)

Locate the <Engine> element and add an attribute for jvmRoute:

               <Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">                   .               </Engine>

 

Step 4: Configure JBoss session to add jvmRoute to the sessions

 

 

Finally, we need to tell JBoss Web to add the jvmRoute value to its session cookies so that mod_proxy_balancer can route incoming requests.

 

Edit JBOSS_HOME/server/all/deploy/jboss-web.deployer/META-INF/jboss-service.xml (replace /all with your own server name)

 

Locate the attribute element with a name of UseJK, and set its value to "true":

 

<attribute name="UseJK">true</attribute>

 

Using mod_proxy with AJP:

 

Step 1: See Using mod_proxy with http/https (above)

 

Step 2: Setup Apache to use mod_proxy (AJP)

 

 

Make sure that at least following modules are loaded (uncomment this in httpd.conf)

 

     LoadModule proxy_module modules/mod_proxy.so     LoadModule proxy_balancer_module modules/mod_proxy_balancer.so     LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

 

Add those lines in APACHE_HOME/conf/httpd.conf :

 

     <Proxy balancer://mycluster>       Order deny,allow          Allow from all          BalancerMember ajp://localhost:8009/jmx-console          BalancerMember ajp://localhost:8109/jmx-console     </Proxy>          ProxyPass /jmx-console balancer://mycluster

 

Step 3: See Using mod_proxy with http/https (above)

 

Step 4: See Using mod_proxy with http/https (above)

 

When to use mod_jk and when to use mod_proxy for load-balancing

 

 

  • Load balancing is definitely easier to configure using mod_proxy as compared to mod_jk1.x.

  • mod_proxy works well since version 2.2.2 of Apache httpd. Don't use mod_proxy with older version of Apache httpd.

  • mod_jk is in continous development phase and is tried and tested by many people arround the world. mod_proxy is fairly new.

  • mod_proxy_http doesn't forward the SSL information to JBoss Web (See Forwarding SSL environment when using http/https proxy )

  • mod_proxy allows to use https between Apache httpd and JBoss Web (See Encrypting connection between httpd and TC).

 

If you decide to use mod_proxy, you have two options for load-balancing

 

 

When to use mod_proxy + mod_proxy_http and mod_proxy + mod_proxy_ajp for load-balancing

 

 

  • AJP is binary, so there was the transmission savings

  • JBoss Web could handle AJP faster and more efficiently than HTTP (the AJP endpoints were quicker than the HTTP endpoint implementations)

  • However mod_proxy_http now implements connection pooling and load balancing so one needs to test mod_proxy_http as well as mod_proxy_ajp before deciding

 

 

Here is the FAQ on mod_proxy_ajp vs mod_jk

 

Using sticky sessions:

 

Add stickysession parameter to ProxyPass

        ProxyPass /jmx-console balancer://mycluster stickysession=JSESSIONID lbmethod=bytraffic nofailover=Off 

 

Sticky Session is supported by mod_proxy_http as well as mod_proxy_ajp

 

  • Note:* If you are using mod_proxy_http you have to create one ProxyPassReverse for each BalancerMember you define in the balancer.

 

Going over the 8K AJP headers limits:

The default size of a AJP package is 8K as the http headers are sent only in the first packet it could be needed to overcome the limit.

 

To reach this you need to add packetSize parameter in the <Connector/> parameter like:

 

    <Connector port="8009" protocol="AJP/1.3"               packetSize="20000"               redirectPort="8443" ></Connector>

and ProxyIOBufferSize (also LimitRequestFieldsize probably) directive in httpd.conf too. For example:

 

ProxyIOBufferSize 19000LimitRequestFieldsize 18000

packetSize is supported since Tomcat 5.5.21 and Tomcat 6.0.1.

 

Old version of httpd-2.2.x (x<5) need a patch to support this extension. You find the patch at http://people.apache.org/~jfclere/patches/ProxyIOBufferSize.patch

平均用户评价
(1 评价)
评论 (10)
  • Brian Holland

    Brian Holland 2009-4-24 上午12:06

    Where does the text in Step 2 the second text snippet go?

    <Proxy balancer://mycluster>

    ...

     

    Does it go in the http.conf file as well, if so where exactly.

  • Sham Gatupa

    Sham Gatupa 2009-7-30 下午1:56 (回复 Brian Holland)

    Brian, Yes, it should be in conf file. For little elegance in organizing the config information,

    create another file(any name is good) vitual_proxy.conf and include this at the end in httpd.conf file

  • Tiago Emerick

    Tiago Emerick 2011-5-20 下午3:51 (回复 Sham Gatupa)

    Sorry for reply an old post, but i need help.

     

    I have to do this configuration, but in my case im using mod_cluster.

    Do you know something about?

     

    Anyway... using this confg posted here, doesnt work.

     

    Any help?

    Sorry again.

  • Tiago Emerick

    Tiago Emerick 2011-5-20 下午4:01

    sorry again.

     

    just being more specific, i have to do the same as you do here:

    Using mod_proxy whith AJP

     

     

    But in my case, is mod_cluster

  • Jean-Frederic Clere

    Jean-Frederic Clere 2011-5-23 上午7:55 (回复 Tiago Emerick)

    for mod_cluster please look to mod_cluster documentation. http://docs.jboss.org/mod_cluster/1.1.0/html/

  • Sergiu Pienar

    Sergiu Pienar 2011-6-21 上午7:25

    Hi,

     

    I can not find JBOSS_HOME/server/all/deploy/jbossweb-web.deployer/server.xml but only JBOSS_HOME/server/all/deployers/jboss-web.deployer but this golder does not contain a server.xml file.

    I'm using JBoss 5.1.0.GA.

     

     

    Am I missing something ?

  • Mark DeSpain

    Mark DeSpain 2011-6-29 上午1:10

    In the section "Using mod_proxy with http/https", I think the ProxyPass directive should actually be the same as what it is for the AJP section:

     

       ProxyPass /jmx-console balancer://mycluster

     

    as opposed to

     

       ProxyPass /jmx-console balancer://mycluster/jmx-console

     

     

    Otherwise, incoming requests will be unintentionally mapped to /jmx-console/jmx-console instead of just /jmx-console, due to the BalancerMember directives also having /jmx-console at the end.

     

    BalancerMember http://host1:8080/jmx-console route=node1

  • Jean-Frederic Clere

    Jean-Frederic Clere 2011-6-29 上午2:10 (回复 Mark DeSpain)

    Fixed.

  • Hendi Marcos Silva

    Hendi Marcos Silva 2012-5-7 下午1:57 (回复 Jean-Frederic Clere)

    Using mod_proxy with http/https

     

    did not work well ProxyPass /jmx-console balancer://mycluster

    I went back to the ProxyPass /jmx-console balancer://mycluster/jmx-console

  • Anoop Rathi

    Anoop Rathi 2012-8-15 下午2:51

    Sorry for putting it up here on such old post but I need to implement reverse proxy setup so that I can get rid of the JBoss instance port number from the URL once the Apache hits the JBoss.I was using mod_jk but unable to find the proxy setup anywhere.

     

    I am using JBoss Eap 5.1 and Apache Tomcat 2.2.21 Where do I put the following configuration

     

    1)  ProxyPass /jmx-console balancer://mycluster lbmethod=byrequests stickysession=JSESSIONID|jsessionid

     

    2) I didnt find the file on path specified. Its inside conf folder for me.

     

    Edit JBOSS_HOME/server/all/deploy/jboss-web.deployer/META-INF/jboss-service.xml (replace /all with your own server name)

     

    3) I didnt find below entry anywhere to make it true.

    <attribute name="UseJK">true</attribute>

     

    please respond to these questions.

     

    Thanks!

原创粉丝点击