Search code examples
apachejakarta-eemod-proxy

How to configure Apache to work as proxy (load balancer) for j2ee server?


I have apache web server installed as frontend and I have j2ee SAP Netweaver Application Server installed in Intranet server. How can I configure apache to forward requests and response to/from j2ee app server. for example, external apache server's ip is 9.20.1.1:80. internal sap server's address is 192.168.0.1/sap/bc/gui/sap/its/webgui?sap_client=200 I want access to my sap app server for example 9.20.1.1/sapserver/sap/bc/gui/sap/its/webgui?sap_client=200


Solution

  • You mentioned load balancing- so presumably you want to be able to add more Application Servers that are served through a single address. I hope they are stateless or storing session information in a database. You can use Apache to serve as a reverse proxy load balancer with mod_proxy_balancer. Docs are here.

    Here's an example of what to add to your httpd.conf from this link.

     <Proxy balancer://myclustername>
      # cluster member 1
      BalancerMember http://192.168.0.1:3000 
      BalancerMember http://192.168.0.1:3001
    
      # cluster member 2, the fastest machine so double the load
      BalancerMember http://192.168.0.11:3000 loadfactor=2
      BalancerMember http://192.168.0.11:3001 loadfactor=2
    
      # cluster member 3
      BalancerMember http://192.168.0.12:3000
      BalancerMember http://192.168.0.12:3001
    
      # cluster member 4
      BalancerMember http://192.168.0.13:3000
      BalancerMember http://192.168.0.13:3001
    </Proxy>
    
    <VirtualHost *:80>
      ServerAdmin info@meinprof.de
      ServerName www.meinprof.de
      ServerAlias meinprof.de
      ProxyPass / balancer://meinprofcluster/
      ProxyPassReverse / balancer://meinprofcluster/
      ErrorLog /var/log/www/www.meinprof.de/apache_error_log
      CustomLog /var/log/www/www.meinprof.de/apache_access_log combined
    </VirtualHost>