HAProxy Configuration Guide

This guide provides detailed instructions for configuring HAProxy to expose both the Runtime API and the Statistics page, which are required for the HAProxy MCP Server to function properly.

Table of Contents

Runtime API Configuration

HAProxy's Runtime API allows for dynamic configuration changes and monitoring without restarting the service. The HAProxy MCP Server requires access to this API to function properly.

TCP Socket Mode

To expose the Runtime API over a TCP socket, add the following to your haproxy.cfg:

global
    # Other global settings...
    
    # Runtime API configuration
    stats socket [email protected]:9999 level admin
    # OR for more secure setup, bind to localhost only
    # stats socket [email protected]:9999 level admin

For HAProxy 2.0 and later, you can also use:

Unix Socket Mode

For Unix socket mode, which provides better security as it's file-system based:

Ensure that the directory exists and has proper permissions:

Statistics Page Configuration

HAProxy's Statistics page provides a web-based dashboard for monitoring. To enable it, add:

For a more secure setup, restrict access:

Security Considerations

When exposing the Runtime API and Statistics page, consider these security practices:

  1. Authentication: Always use authentication for production environments

  2. Binding: Bind services to localhost or internal IPs only when possible

  3. Firewall Rules: Use firewall rules to restrict access to the Runtime API and Stats ports

  4. TLS/SSL: For statistics page, consider using HTTPS:

  5. Access Control: Limit who can access admin functions:

Combined Configuration Example

Here's a complete example that includes both Runtime API and Statistics page:

Troubleshooting

If you experience issues connecting to the Runtime API or Statistics page:

  1. Check permissions:

    • For Unix sockets: ls -la /var/run/haproxy/admin.sock

    • Ensure the user running the MCP server has access

  2. Verify the socket is listening:

    • For TCP mode: netstat -an | grep 9999

    • For Stats page: netstat -an | grep 8404

  3. Test connections directly:

  4. Check HAProxy logs:

  5. Restart HAProxy after config changes:

For more detailed information, refer to the official HAProxy documentation.

Last updated

Was this helpful?