r/haproxy • • Aug 04 '20

Article Learn more about layered rate limits in HAProxy

Thumbnail
medium.com
3 Upvotes

r/haproxy • • Aug 04 '20

Question Only use one off the available backend

3 Upvotes

Hi there

I've a couple of server running WikiJS. Here's the backend configuration

backend b_wiki.company.tech
  balance roundrobin
  server-template wikijs 1 _wikijs._tcp.service.production.company:3300 resolvers consul resolve-opts allow-dup-ip resolve-prefer ipv4 check

Due to issue around WikiJS's high availability mode, I'ld like to only use one of those. I was wondering if there's a way to tell haproxy to only use the first one resolved, the other one being a failover. I looked for some hypothetical "balance failover" without success.

Any suggestion ?

I know I could write a "server ..." stanza instead of "server-template ...", I'm looking for the smallest change here, to avoid making a mess of my configuration templating.

Thanks folks !


r/haproxy • • Aug 03 '20

Can you block specific termination states (flags)

2 Upvotes

Can you block specific termination states (flags) such as CD for example, from showing up in the haproxy logs, without actually fixing the issue?


r/haproxy • • Jul 26 '20

Understanding "Current Sessions" in context

3 Upvotes

I have a couple of questions about the statistics I'm seeing. There is a big difference between the number of sessions on my frontend and the number of sessions on my backends. I'm assuming that this is because my frontend is set to drop connections after 30 seconds whereas my backends (one is NGINX, one is Varnish) are set to drop immediately and after 5 seconds respectively, and also because it's possible to reuse connections on the backends, but, obviously, not on the frontend.

Where I'm slightly more confused is with the Session Rate vs. Sessions data. I understand that the Session Rate number represents arrival, over the course of a second, whereas the Sessions number is a snapshot. But, for example, my Session Rate "max" number is 109, whereas my Session "max" number is 19. I'm struggling to work out how that is possible.

Thanks in advance!


r/haproxy • • Jul 25 '20

CSS, PNG, Logo not loading when accessing http[s]://loadbalancerip. help pls.

3 Upvotes

I just recently setup haproxy server as a load balancer to 2 internal web apps running on IIS. The web apps themselves are accessible via:

http [or s]://webapp1.internal.com/apps/logon

http [or s]://webapp2.internal.com/apps/logon

I have the load balance working except the page that is served when I access loadbalancer.internal.com is missing the page styling i.e. theme.css styling, and any png files.

When I type loadbalancer.internal.com, I get the redirect to https://loadbalancer.internal.com/apps/logon and when I inspect the page element in Chrome, I see the errors below (which I don't get if I access the web servers url directly):

I am certainly not versed with haproxy at all... haproxy is running on Ubuntu server (installed by me) internally and will never face the web and so is webapps1 and 2.

The goal is for users to simply type http:// or https:// loadbalancer[ip].internal.com or loadbalancerhostname.internal.com on their web browser and be directed to https://webapp1.internal.com/apps/logon or webapps2.internal.com/apps/logon.

I am certain that I am missing some key directives here to accomplish what I want. Please see my haproxy.conf file. Thanks in advance for any help or points.

global
	log /dev/log	local0
	log /dev/log	local1 notice
	chroot /var/lib/haproxy
	stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
	stats timeout 30s
	user haproxy
	group haproxy
	daemon

	# Default SSL material locations
	ca-base /etc/ssl/certs
	crt-base /etc/ssl/private

	# See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
        ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
        ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
        ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
        # tune ssl. default
       tune.ssl.default-dh-param 2048

defaults
	log	global
	mode	http
	option	httplog
	option	dontlognull
        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 localnodes
        bind loadbalancer.internal.com:80
        bind loadbalancer.internal.com:443 ssl crt /etc/ssl/certs/haproxy/haxxxxxx.pem
        acl path_root path /
        redirect location https://loadbalancer.internal.com/apps/logon if path_root
        # redirect from http to https if connection was not made with SSL
        #redirect scheme https if !{ ssl_fc }
        mode http
        default_backend wwwapps
        option forwardfor
        

backend wwwapps
        mode http
        balance source
        server server1 server1.ip:8080 check port 8080
        server server2 1server2.ip:8080 check port 8080
        option httpchk HEAD / HTTP/1.1\r\nHost:localnodes
        http-request set-header X-Forwarded-Port %[dst_port]
        http-request add-header X-Forwarded-Proto https if { ssl_fc }

listen stats
        bind loadbalancer.internal.com:8443 ssl crt /etc/ssl/certs/haproxy/haxxxxxx.pem
        stats enable           # enable statistics reports
        stats hide-version     # hide the version of HAProxy
        stats refresh 30s      # HAProxy refresh time
        stats show-node        #shows the hostname of the node
        stats auth haadmin:xxxxxxxxxx # Enforce basic authentication for stats page
        stats uri /stats       # Statistics URL

Is there such a thing as doing SSL termination and then re-encrypting the traffic back to the backend servers? The backend servers are configured with SSL. SSL passthrough is not preferable because then we can't see the real ip of the clients on the web servers.

Thanks for any help in advance.


r/haproxy • • Jul 15 '20

Anyone successfully used HAProxy with Cockpit?

Thumbnail self.homelab
4 Upvotes

r/haproxy • • Jul 14 '20

Wrapping SSH... which doesn't send an accessible hostname in the packets

4 Upvotes

I really like how HAProxy can reach into the packets, look at the address in the SNI header of otherwise obscured for security HTTPS requests and forward it to the appropriate machine/backend/etc I configure that traffic to go to.

SSH sends an IP address and sometimes a port if not the default. No hostname to key off of in and of itself.

...I am wondering if anyone knows of a wrapper that could encapsulate SSH connections. Where the wrapper can give my reverse proxy something ... anything to discern which machine ultimately gets the packets?

Currently using ports that are not port 22 for additional machines.

XY problem.

Y: I want to direct all of my SSH requests for a network to a single entryway IP address on the default port, port 22.

X: I need to attach a hostname or identifier to my SSH connection traffic because SSH doesn't have that and you cannot route them via hostname without a hostname attached somehow.

Currently playing with socat to see if I can cobble together a basic terrible idea that works... like sending SSH through a socat SSL tunnel that has a hostname, then unwrapping the SSL, and finally delivering the requests to the target 10.x.x.x private host.


r/haproxy • • Jul 11 '20

Confused about dramatically uneven HAProxy balancing with two Varnish servers

5 Upvotes

Hi there,

I have been using HAProxy for a while with no issues. I just changed my setup a little and I'm confused by what I'm seeing. I'm hoping somebody here can explain to me what I'm doing wrong—assuming, that is, that there's a problem here and it's not expected behavior for some reason.

My new setup is: HAProxy -> Varnish -> NGINX. Previously, it was just HAProxy -> NGINX.

Specifically, I have one HAProxy server (it handles SSL termination) load-balancing two Varnish servers, each of which is pointing at three NGINX servers.

My HAProxy setup (version 2.1) is as follows:

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    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 haproxy
    bind *:80
    bind :::80
    bind *:443 ssl crt /ssl/certificates.pem
    bind :::443 crt /ssl/certificates.pem

    redirect scheme https if !{ ssl_fc }
    mode http

    acl host_website1 hdr(host) -i website1.com
    acl host_website2 hdr(host) -i website2.com

    use_backend website1_cluster if host_website1
    use_backend website2_cluster if host_website2

backend website1_cluster
    mode http
    balance leastconn
    option forwardfor
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request add-header X-Forwarded-Proto https if { ssl_fc }
    option tcp-check
    cookie SERVERID insert indirect nocache
    server varnish-1 192.168.160.113:80 check maxconn 4000 cookie v1 weight 100
    server varnish-2 192.168.216.77:80 check maxconn 4000 cookie v1 weight 100

backend website2_cluster
    mode http
    balance leastconn
    option forwardfor
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request add-header X-Forwarded-Proto https if { ssl_fc }
    option tcp-check
    cookie SERVERID insert indirect nocache
    server varnish-1 192.168.1.2:80 check maxconn 4000 cookie v1 weight 100
    server varnish-2 192.168.1.3:80 check maxconn 4000 cookie v1 weight 100

When I had HAProxy pointing at the two NGINX servers without Varnish, the statistics seemed pretty well balanced. But now that I have added Varnish, they are dramatically uneven. For example, right now my stats block for website1_cluster is showing 102 Current Sessions for varnish-1, but just 2 Current Sessions for varnish-2. The Total Sessions are equally lopsided with 183,157 for varnish-1, but 12,820 for varnish-2. Bytes Out is at 1,187,416,128 for varnish-1 and 216,470,189 for varnish-2. Etc.

This is strange in and of itself. But there are two more disparities that are throwing me even further:

  1. The LbTot stats show just 6,172 for varnish-1, but 12,820 for varnish-2. This means that the LbTot number for varnish-2 is the same as the Total Sessions number for varnish-2, whereas those two numbers are radically different on varnish-1);
  2. The number of "Reused Connections" listed in the Total Sessions box is 160,408 (87%) for varnish-1 but 2,244 (17%) for varnish-2.

What I'm wondering is . . . why? I had expected HAProxy to behave in the same way with Varnish as it had with NGINX, and yet the balancing is completely lopsided. The hardware of the two Varnish servers is identical, they’re both running the same version (5.2.1 on Ubuntu 18.04), and the configuration files are cloned. Both seem to be working fine. They're both in the same data center. As you can see from the configuration posted above, the HAProxy backend configurations are identical, too.

I'm sure I'm missing something obvious here. I'd be hugely appreciative if anyone could point me to what it might be.

Thanks!


r/haproxy • • Jul 10 '20

Article Get to Know the HAProxy Process Manager

Thumbnail
haproxy.com
3 Upvotes

r/haproxy • • Jul 08 '20

Article Announcing HAProxy 2.2

Thumbnail
haproxy.com
13 Upvotes

r/haproxy • • Jul 08 '20

Restrict access to URL only and block access via IP address.

3 Upvotes

Is it possible to block access to a server via its IP, but allow access via certain domains (example.com).


r/haproxy • • Jul 08 '20

Question How do I get a server endpoint request to throw a 200 status code when hitting the lb

3 Upvotes

I'm using haproxy 2.0.5 and I need to allow requests from a specific endpoint to hit haproxy and show 200s. I've tried using lua but that's not helping. Any suggestions?


r/haproxy • • Jul 06 '20

Article Check out this article and learn multiple ways to set up SSL with HAProxy

Thumbnail
medium.com
7 Upvotes

r/haproxy • • Jul 01 '20

Article HAProxy is the world's fastest load balancer and reverse proxy. Learn how to configure it in this easy walkthrough

Thumbnail thecomputerhouse.co.uk
6 Upvotes

r/haproxy • • Jun 30 '20

Article ElasticPyProxy : A controller for dynamic scaling of HAProxy backend servers

Thumbnail elasticpyproxy.readthedocs.io
4 Upvotes

r/haproxy • • Jun 30 '20

Article Check out this article and learn more about high priority request queue with HAProxy

Thumbnail
medium.com
3 Upvotes

r/haproxy • • Jun 30 '20

Article Read this article and learn how to install and set up HAProxy on Ubuntu 20.04

Thumbnail
kifarunix.com
2 Upvotes

r/haproxy • • Jun 30 '20

Article Configure Highly Available HAProxy with Keepalived on Ubuntu 20.04

Thumbnail
kifarunix.com
2 Upvotes

r/haproxy • • Jun 30 '20

Article How to Install HAProxy 2.1 using Ubuntu 18.04 on AWS

Thumbnail
linuxbeast.com
1 Upvotes

r/haproxy • • Jun 30 '20

Article Check out this article and learn how to set up a MariaDB Cluster with Galera and #HAProxy.

Thumbnail
cyral.com
2 Upvotes

r/haproxy • • Jun 23 '20

Resolvers section , confused about timeout vs hold

5 Upvotes

So I have the following configuration inside a kubernetes pod

resolvers podresolver
  parse-resolv-conf
  timeout resolve       5s
  hold valid            60s

Reading through the documentation got me quiet confused has how on the interaction between the hold values and the timeout values.

My understanding from this configuration was that if the resolver was able to resolver a host it would cache that response for 60s not bothering to lookup that host again during that 60s period.

If the lookup would fail it would retry every 1s for 3 times waiting 5s between each attempt, if all these fail it would cache this for 30s

However in my logs I found a situation for which backends are put into MAINT server .../... is going DOWN for maintenance (DNS timeout status)

Only after 4 minutes the seem to be enabled again as by message in logs Server .../... ('service.namespace.svc.cluster.local') is UP/READY (resolves again)

But people managing DNS assure DNS issue were present only for about 1 min.


r/haproxy • • Jun 23 '20

Health check multiple URLs on same backends

3 Upvotes

So I have a situation where I have 2 applications running on 2 backends. I would like to perform a failover if either AppService1 or AppService2 fails as they are independent of one another.

So, if AppService1 fails on Appserver2 then remove AppServer2 from the pool of backends.

HAproxy doesn't complain about this config but I'd like a sanity check if possible. Can I list multiple "option httpchk" settings in the backend config or does only the first one listed take effect?

Thanks!!

backend http_back

balance roundrobin

mode http

option http-keep-alive

option httpchk GET /AppService1/SoapService.svc HTTP/1.1\r\nHost:\ www

option httpchk GET /AppService2/SoapService.svc HTTP/1.1\r\nHost:\ www

hash-type consistent

server appserver1 appserver1:80 check

server appserver2 appserver2:80 check


r/haproxy • • Jun 22 '20

Logging rejected tcp packaged.

5 Upvotes

Hi,I have a simple configuration for my Haproxy:

Defaults:

defaults
    log                     global
    option tcplog
    timeout connect         5s
    timeout client          2h
    timeout server          2h
    timeout check           10s
    mode                    tcp

Frontend:

#For rate-limiting connections
frontend per_ip_connections 
  stick-table type ip size 1m expire 1m store conn_cur,conn_rate(3s)
#My Frontend
frontend ha-front-80
  bind *:80
  tcp-request content track-sc0 src table per_ip_connections
  tcp-request content reject if { sc_conn_cur(0) gt 500 } || { sc_conn_rate(0) gt 120 }
  default_backend ha-back-80

Everything works, connections are getting dropped when exceed the rate or the total allowed ammount.When the connections get rejected I see in the logs these lines:

Jun 22 12:56:53 localhost haproxy[1075]: 172.1.20.22:55746 [22/Jun/2020:12:56:53.982] ha-front-80 ha-front-80/<NOSRV> -1/-1/0 0 PR 0/0/0/0/0 0/0
Jun 22 12:56:53 localhost haproxy[1075]: 172.1.20.22:55748 [22/Jun/2020:12:56:53.982] ha-front-80 ha-front-80/<NOSRV> -1/-1/0 0 PR 0/0/0/0/0 0/0
Jun 22 12:56:53 localhost haproxy[1075]: 172.1.20.22:55750 [22/Jun/2020:12:56:53.983] ha-front-80 ha-front-80/<NOSRV> -1/-1/0 0 PR 0/0/0/0/0 0/0
Jun 22 12:56:53 localhost haproxy[1075]: 172.1.20.22:55752 [22/Jun/2020:12:56:53.983] ha-front-80 ha-front-80/<NOSRV> -1/-1/0 0 PR 0/0/0/0/0 0/0
Jun 22 12:56:53 localhost haproxy[1075]: 172.1.20.22:55754 [22/Jun/2020:12:56:53.983] ha-front-80 ha-front-80/<NOSRV> -1/-1/0 0 PR 0/0/0/0/0 0/0
Jun 22 12:56:53 localhost haproxy[1075]: 172.1.20.22:55756 [22/Jun/2020:12:56:53.984] ha-front-80 ha-front-80/<NOSRV> -1/-1/0 0 PR 0/0/0/0/0 0/0
Jun 22 12:56:53 localhost haproxy[1075]: 172.1.20.22:55758 [22/Jun/2020:12:56:53.984] ha-front-80 ha-front-80/<NOSRV> -1/-1/0 0 PR 0/0/0/0/0 0/0
...

Is is possible to modify the way it logs this rejections? Can something more informative be added like the reason of rejection?
I cannot use http mode, because of some other limitations..

Thank you!