Connect haproxy tcp socket

This shows how to connect your application listening on TCP port <port number> (started with "-p" option in mrim) to HAProxy load balancer.

One use of HAProxy is to balance the load between different web servers, which in turn are connected to your RimStone applications; in this case HAProxy does not directly communicate with your RimStone applications (which are behind other web servers).

However, when you want HAProxy to directly communicate with your RimStone application servers, you may use configuration similar to this (shown is just a bare-bone setup needed to accomplish the goal, note sections "frontend", "fcgi-app" and "backend" that are relevant to RimStone). The HAProxy configuration file is typically in "/etc/haproxy/haproxy.cfg":
global
    user haproxy
    group haproxy
    daemon

defaults
    mode    http
    timeout connect 5000
    timeout client  50000
    timeout server  50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

frontend front_server
    mode http
    bind *:90
    use_backend backend_servers if { path_reg -i ^.*\/<your RimStone app name>\/.*$ } 
    option forwardfor

fcgi-app RimStone-fcgi
    log-stderr global
    docroot <user home dir>/.rimstone/apps/<your RimStone app name>/app
    path-info ^.+(/<your RimStone app name>)(/.+)$ 

backend backend_servers                                                                                                                     
    mode http
    filter fcgi-app RimStone-fcgi
    use-fcgi-app RimStone-fcgi
    server s1 127.0.0.1:3000 proto fcgi

Restart HAProxy:
sudo systemctl restart haproxy

Note that RimStone application path is "/<your RimStone app name>" (and the application name may or may not be the same, see request). The TCP port of the application is "3000" (could be any port number you choose that's greater than 1000 and lower than 65535).

HAProxy itself is bound to port 90 in this example (see "frontend" section above), and "path_reg" specifies which URLs will be passed to your RimStone application (i.e. they must have "/<your RimStone app name>/" in the URL). "path-info" specifies SCRIPT_NAME and PATH_INFO (as "()" regular sub-expressions), which are as such passed to your RimStone application. "docroot" is set to the application home directory (see directories) in case you wish to serve HTML documents from it; however if you keep sensitive data there, specify another directory.

A RimStone application (named "<your RimStone app name>") would have been started with (using the same application name "<your RimStone app name>" and TCP port "3000"):
mrim -p 3000 <your RimStone app name>

Now you should be able to connect and load-balance your RimStone application servers directly from HAProxy (which in this example listens on port 90, so you'd refer to it with https://your-web-server:90/<your RimStone app name>/...).
See also
Web servers
connect-apache-tcp-socket  
connect-apache-unix-socket  
connect-haproxy-tcp-socket  
connect-nginx-tcp-socket  
connect-nginx-unix-socket  
See all
documentation


Copyright (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.