Skip to content

HAProxy Firewall Port Requirements

HAProxy Firewall Port Requirements in HAProxy Guide.

5 min read Updated SS MR

HAProxy Firewall Port Requirements#

To ensure proper communication between HAProxy and backend servers, certain firewall ports need to be open. For a detailed list of required ports and their respective purposes, refer to the "HEAL Firewall Port Requirements" Excel.

Functionalities#

SSL/TLS Termination#

HAProxy can terminate SSL/TLS connections at the proxy layer, decrypting incoming HTTPS traffic and forwarding plain HTTP to backend servers:

frontend https_front
        bind *:443 ssl crt /etc/haproxy/certs/heal-platform.pem
        mode http
        default_backend heal_servers

Note:

The PEM file must contain the full certificate chain: server certificate and the private key, concatenated in that order.

Access Control Lists (ACLs)#

ACLs allow HAProxy to make routing decisions based on request attributes:

frontend http_front
        bind *:80
        mode http

        # Route based on URL path
        acl is_api path_beg /api
        acl is_grafana path_beg /grafana
        acl is_static path_end .css .js .png .jpg .gif

        use_backend api_servers if is_api
        use_backend grafana_servers if is_grafana
        use_backend static_servers if is_static
        default_backend heal_servers

HTTP Header Manipulation#

HAProxy can add, modify, or remove HTTP headers for security and routing purposes:

# Add security headers
http-response set-header X-Frame-Options SAMEORIGIN
http-response set-header X-Content-Type-Options nosniff
http-response set-header X-XSS-Protection "1; mode=block"
http-response set-header Strict-Transport-Security "max-age=31536000; includeSubDomains"

# Forward client IP to backend
http-request set-header X-Forwarded-For %[src]
http-request set-header X-Real-IP %[src]

Statistics Dashboard#

HAProxy provides a built-in web-based statistics dashboard for real-time monitoring:

listen stats
        bind *:8404
        mode http
        stats enable
        stats uri /stats
        stats refresh 10s
        stats admin if LOCALHOST
        stats auth admin:<password>

The statistics dashboard displays:

  • Frontend and backend server status (UP/DOWN).
  • Current session count and session rate.
  • Request and response byte counters.
  • Error rates (4xx, 5xx responses).
  • Health check status and last status change time.

HTTP Compression#

HAProxy can compress HTTP responses to reduce bandwidth consumption:

defaults
        compression algo gzip
        compression type text/html text/plain text/css application/javascript application/json

Configuration#

Follow the steps below to configure HAProxy for a HEAL platform deployment:

1. Log in to the HAProxy server.

2. Navigate to the path below:

//Appsone_Service/conf/HAPROXY

Copy

3. Take a backup of the existing haproxy.cfg file.

4. Open the haproxy.cfg file.

5. Modify the section below under "frontend HTTP2_frontend".

http-response set-header Strict-Transport-Security "max-age=31536000; includeSubDomains"

6. Remove the above entry and add the following configurations:

http-response set-header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
http-response set-header X-Content-Type-Options "nosniff"
http-response set-header Referrer-Policy "strict-origin-when-cross-origin"
http-response set-header Permissions-Policy "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=(), interest-cohort=()"
http-response set-header Cross-Origin-Opener-Policy "same-origin"
http-response set-header Cross-Origin-Resource-Policy "same-origin"
http-request deny deny_status 405 if { method TRACE } || { method TRACK }

Copy

7. Add the below configuration for all the frontend sections:

http-response set-header X-Frame-Options SAMEORIGIN
http-response set-header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
http-response set-header X-Content-Type-Options "nosniff"
http-response set-header Referrer-Policy "strict-origin-when-cross-origin"
http-response set-header Permissions-Policy "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=(), interest-cohort=()"
http-response set-header Cross-Origin-Opener-Policy "same-origin"
http-response set-header Cross-Origin-Resource-Policy "same-origin"
http-request deny deny_status 405 if { method TRACE } || { method TRACK }

Copy

For example:

The default frontend for OTEL is as follows:

frontend opentelemetry_grpc_frontend
   bind :14250 proto h2
   mode http
   default_backend otel_grpc_backend_service

Copy

update to:

frontend opentelemetry_grpc_frontend 
  bind:14250 proto h2 
  mode http 
  default_backend otel_grpc_backend_service 
  http-response set-header X-Frame-Options SAMEORIGIN 
  http-response set-header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" 
  http-response set-header X-Content-Type-Options "nosniff" 
  http-response set-header Referrer-Policy "strict-origin-when-cross-origin" 
  http-response set-header Permissions-Policy "accelerometer=(), camera=(), geolocation=(), gyroscope=(),    magnetometer=(), microphone=(), payment=(), usb=(), interest-cohort=()" 
  http-response set-header Cross-Origin-Opener-Policy "same-origin" 
  http-response set-header Cross-Origin-Resource-Policy "same-origin" 
  http-request deny deny_status 405 if { method TRACE } || { method TRACK }

Copy

8. Once changes are updated, save the file.

9. Make sure that haproxy.cfg is updated with the same configuration in both nodes in case of HAProxy.

10. Restart the haproxy.nomad file.

HEAL UI Updates#

Follow the changes below to be performed in HEAL UI:

1. Open the UI2x Nomad file.
2. In the volumes section, comment on the line below:

"<Installation_path>/conf/UI2X/nginx.conf:/etc/nginx/conf.d/default.conf"

3. Save the file.

Max Connections and Timeout Tuning#

1. Open the HAProxy configuration file:

sudo vi /etc/haproxy/haproxy.cfg

2. Configure the global and defaults sections:

For Max connections: maxconn

For timeout tunings: timeout connect, timeout client, and timeout server.

global
        log           /dev/log local0
        log           /dev/log local1 notice
        chroot        /var/lib/haproxy
        pidfile       /var/run/haproxy.pid
        maxconn       4096
        user          haproxy
        group         haproxy
        daemon

        # SSL tuning
        ssl-default-bind-ciphers ECDHE+AESGCM:DHE+AESGCM
        ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
        tune.ssl.default-dh-param 2048

defaults
        log       global
        mode      http
        option    httplog
        option    dontlognull
        option    forwardfor
        option   http-server-close
        timeout connect 5000ms
        timeout client   50000ms
        timeout server   50000ms
        retries 3

Configuring Frontend and Backend for HEAL#

1. Configure the HTTP frontend to redirect to HTTPS:

frontend http_front
        bind *:80
        mode http
        http-request redirect scheme https unless { ssl_fc }

2. Configure the HTTPS frontend with SSL termination:

frontend https_front
        bind *:443 ssl crt /etc/haproxy/certs/heal-platform.pem
        mode http

        # ACL-based routing
        acl is_grafana path_beg /grafana
        acl is_api path_beg /api
        acl is_opensearch path_beg /opensearch

        use_backend grafana_backend if is_grafana
        use_backend api_backend if is_api
        use_backend opensearch_backend if is_opensearch
        default_backend heal_ui_backend

3. Configure backend server pools:

backend heal_ui_backend
        mode http
        balance roundrobin
        option httpchk GET /health
        http-check expect status 200
        cookie SERVERID insert indirect nocache
        server heal-ui-1 <HEAL_SERVER_1_IP>:<PORT> check cookie s1 inter 2000 fall 3 rise 2
        server heal-ui-2 <HEAL_SERVER_2_IP>:<PORT> check cookie s2 inter 2000 fall 3 rise 2

backend grafana_backend
        mode http
        balance roundrobin
        option httpchk GET /api/health
        server grafana-1 <GRAFANA_IP>:3000 check inter 2000 fall 3 rise 2

backend api_backend
        mode http
        balance leastconn
        option httpchk GET /health
        server api-1 <API_SERVER_1_IP>:<PORT> check inter 2000 fall 3 rise 2
        server api-2 <API_SERVER_2_IP>:<PORT> check inter 2000 fall 3 rise 2

backend opensearch_backend
        mode http
        balance roundrobin
        server os-1 <OPENSEARCH_IP>:9200 check inter 5000 fall 3 rise 2

HAProxy Troubleshooting#

For HAProxy troubleshooting details, refer to the HAProxy Issues document.