Parameter settings


Timeout
Load Balancer

Apache mod_proxy and proxy_balancer_module settings

Copy this in your proxy-webobjects.conf file for your Apache 2.x WebServer:

More proxy pass parameters are described here.

If you run your application on different machines be shure your applications use differen ports!

Don't forget to remove mod_webobjects.so and your old webobjects.conf.

Common configuration

Needed apache modules

Insert the following in your httpd.conf file

<IfModule proxy_module>
# Turn Forward Proxy off
ProxyRequests Off

# We want all previous proxy routes
ProxyVia Full

# Just in case: Deny proxy access
<Proxy *>
    Order deny,allow
    Deny from none
    Allow from localhost
</Proxy>

# Balancer-manager: Allowed only from localhost
<Location /balancer-manager>
    SetHandler balancer-manager

    Order deny,allow
    Deny from none
    Allow from localhost
</Location>

# Include conf/extra/proxy-webobjects.conf
# Mac OSX ->
# Include /private/etc/apache2/extra/proxy-webobjects.conf

</IfModule>
    

Changes in your Application class

    public Application() {
        super();
        ...
        NSNotificationCenter.defaultCenter().addObserver(this, new NSSelector("addBalancerRouteCookieByNotification", new Class[] { NSNotification.class }),
            WORequestHandler.DidHandleRequestNotification, null);
    }
     
    private String _proxyBalancerRoute = null;
    private String _proxyBalancerCookieName = null;
    private String _proxyBalancerCookiePath = null;

    public void addBalancerRouteCookieByNotification(NSNotification notification) {
        if (notification.object() instanceof WOContext) {
            addBalancerRouteCookie((WOContext) notification.object());
        }
    }

    public void addBalancerRouteCookie(WOContext context) {
        if (context != null && context.request() != null && context.response() != null) {
            if (_proxyBalancerRoute == null) {
                _proxyBalancerRoute = (name() + "_" + port().toString()).toLowerCase();
                _proxyBalancerRoute = "." + _proxyBalancerRoute.replace('.', '_');
            }
            if (_proxyBalancerCookieName == null) {
                _proxyBalancerCookieName = ("routeid_" + name()).toLowerCase();
                _proxyBalancerCookieName = _proxyBalancerCookieName.replace('.', '_');
            }
            if (_proxyBalancerCookiePath == null) {
                _proxyBalancerCookiePath = (System.getProperty("FixCookiePath") != null) ? System.getProperty("FixCookiePath") : "/";
            }
        }
        WOCookie cookie = new WOCookie(_proxyBalancerCookieName, _proxyBalancerRoute, _proxyBalancerCookiePath, null, -1, context.request().isSecure(), true);
        cookie.setExpires(null);
        context.response().addCookie(cookie);
    }

If you need the client ip you need to ask for 'x-forwarded-for' e.g.:

    public static String clientIP(WORequest request) {
        Object ipAddress = request.headerForKey("x-forwarded-for");
        if (ipAddress != null && ipAddress.toString().length() > 0) {
            ipAddress = StringUtils.split(ipAddress.toString(), ',')[0];
        }
        if (ipAddress == null) {
            ipAddress = request._remoteAddress();
            if (ipAddress == null) {
                ipAddress = request._originatingAddress();
                if (ipAddress == null) {
                    ipAddress = request.headerForKey("remote_host");
                }
                else {
                    ipAddress = ((InetAddress) ipAddress).getHostAddress();
                }
            }
        }
        if (ipAddress != null) {
            return ipAddress.toString();
        }
        return null;
    }

URL rewrite rules

If you want to rewrite your application URLs from /cgi-bin/WebObjects/YourApp.woa to /yourapp, you can set the following properties and add the apache rewrite rule

Error handling


Examle to add your own error pages

    # error folder
    <Location "/errors">
        Options -Indexes
        Order Deny,Allow
        Allow from all
    </Location>
    
    # Proxy everything except for /error
    ProxyPass /errors !

    # Service unavailable
    ErrorDocument 503 /errors/error503.html

More information


Basic


proxy
balancer

Load balancing methods


requests
traffic
busyness
heartbeat