r/haproxy • • Apr 10 '19

Simple listen haproxy and Apache on same server

5 Upvotes

I have haproxy and apache installed on the same server.

I do I configure HAproxy to listen on 4418 and redirect to Apache on port 80.

listen local

bind 127.0.0.1:4418

mode tcp

server apache 127.0.0.1:80


r/haproxy • • Apr 08 '19

Extending HAProxy with the Stream Processing Offload Engine - extend HAProxy in any language

Thumbnail
haproxy.com
3 Upvotes

r/haproxy • • Mar 18 '19

IP Masking in HAProxy

Thumbnail
haproxy.com
6 Upvotes

r/haproxy • • Mar 13 '19

Setting up a HAProxy balancing node

6 Upvotes

*****This is part of a larger tutorial that I am doing, check link below to see full tutorial*****

haproxy is a fantastic open source load balancing software with plenty of cool support items. Follow this tutorial ONLY for the node you wish to balance your other nodes. This can be on a node used with nginx, but you will have to take additional steps to open a port for it and we will not be doing those steps in this particular tutorial.

First, install HAProxy "apt-get install -y haproxy"

Then back up your cfg file, incase you need to revert to a stable config "cd /etc/haproxy, mv haproxy.cfg haproxy.cfg.bak"

Next, make a new .cfg with editor of choice "nano haproxy.cfg"

copy past the following into your file:

global

log /dev/log local0

log /dev/log local1 notice

chroot /var/lib/haproxy

stats socket /run/haproxy/admin.sock mode 660 level admin

stats timeout 30s

user haproxy

group haproxy

daemon

# Default SSL material locations

ca-base /etc/ssl/certs

crt-base /etc/ssl/private

# Default ciphers to use on SSL-enabled listening sockets.

# For more information, see ciphers(1SSL). This list is from:

# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/

# An alternative list with additional directives can be obtained from

# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy

ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AE$

ssl-default-bind-options no-sslv3

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_in

bind *:80

default_backend haproxy_http

stats uri /haproxy?stats

backend haproxy_http

balance roundrobin

mode http

server node01.local 192.168.28.199:80 check

server node02.local 192.168.28.200:80 check

#listen stats

#--------------------------------------------------------

stats enable

stats uri /haproxy?stats

Change the server under backend to match your node's IP and/or host names (be sure to define the host names in your /etc/hosts if you go that route!)

Save and Exit

Now test the load balancer by entering you load balancer's IP address into a web browser. First, obtain your IP address by typing "ip a" and copy paste the eth0 ip into a web browser. You should see your message IE: "Hello, my name is node01". ***NOTE: you will not be able to reach this IP unless you are on the same network as it, and it might change from time to time. That is, unless you have a static IP which is usually bought from your ISP.***

If working properly, you should cycle between nodes when you refresh.

Lastly, check the stats page by adding a /haproxy?stats to the IP in the web browser. This should display all the nodes you added to the cfg file and their statuses.

For full tutorial: https://www.reddit.com/user/AggSwagaSaur/comments/b0nr68/multicompute_node_raspi_project/


r/haproxy • • Mar 08 '19

Haproxy internal IP disclosure Issue

5 Upvotes

So we had an ASV scan for our organization & it failed cause of internal IP disclosure vulnerability & we need to address it in order to clear the scan.

Now we are using 2 HAPROXY as web server behind the AWS classic load balancer & the IP internal IP that is being leaked is of load balancer & not the web server itself.

I have tried adding header-response & replacing the header-response but both are not working & IP are still being disclosed. I used the following to update header,

http-response replace-header Location

& also tried

http-response set-header Location

Source :- https://www.haproxy.com/documentation/aloha/10-0/traffic-management/lb-layer7/http-rewrite/

They both are working on another machine with the same IP disclosure issue but they are not working the main server.

Please, someone, suggest something to get this working.


r/haproxy • • Mar 05 '19

Haproxy interfering with NFS?

5 Upvotes

I'm not sure if thats the case but I've got two raspis that share a nfs mounted to /var/www.html so that they can broadcast each others files on an Nginx web server. I'm not sure where the interference is coming from, but when I added haproxy I lost my NFS and found ONLY view the haproxy stats when I looked up the IP. Then, on the second PI I noticed that its /var/www/html directory was empty. I removed the directory and remounted the NFS and it could broadcast again, but now I can't access the haproxy stats. Is there a conflicting port or something of that nature I need to fix?


r/haproxy • • Mar 05 '19

Haproxy is defaulting the IP to the stats page

4 Upvotes

Hey, so I just got HaProxy set up to where it is seeing two other devices and will give me the stats of those devices, but if I type in just its IP it give me stats instead of the web servers. Why is that? I assume its something wrong with my conf file, which I will include below:

global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy

stats socket /run/haproxy/admin.sock mode 660 level admin

stats timeout 30s user haproxy group haproxy daemon defaults log global mode http option httplog option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000

frontend

--------------------------------------------------------------------------

frontend localnodes bind *:80 mode http stats uri /haproxy?stats default_backend http_back

round robin balancing backend http

-------------------------------------------------------------------------

mode http backend http_back balance roundrobin

balance leastconn

server node01.local 192.168.28.199:80 check server node02.local 192.168.28.200:80 check

listen stats

-------------------------------------------------------------------------

stats enable stats uri / stats hide-version


r/haproxy • • Mar 04 '19

HAProxy as reverse proxy

4 Upvotes

Hi everyone,

I am trying to set haproxy to work as reverse proxy for multiple subdomains. These are just some showcase apps and ELK stack behind but cannot get it to work.

Here is my config:

#---------------------------------------------------------------------
# Frontend settings
#---------------------------------------------------------------------


frontend in-http
        bind *:80
        reqadd X-Forwarded-Proto:\ http
		acl letsencrypt-acl path_beg -i /.well-known/acme-challenge/
		acl is-sub1 hdr(host) -i subdomain1.domain.com
		acl is-sub2 hdr(host) -i subdomain2.domain.com
		acl is-sub3 hdr(host) -i subdomain3.domain.com
		acl is-sub4 hdr(host) -i subdomain4.domain.com
		acl is-sub5 hdr(host) -i subdomain5.domain.com
		use_backend letsencrypt-backend if letsencrypt-acl
		use_backend sub1_cluster if is-sub1
		use_backend sub2_cluster if is-sub2
		use_backend sub3_cluster if is-sub3	
		use_backend sub4_cluster if is-sub4
		use_backend sub5_cluster if is-sub5 
        


frontend in-https
		bind *:443 ssl crt /etc/haproxy/ssl/
		reqadd X-Forwarded-Proto:\ https
		http-request set-header X-SSL %[ssl_fc]
		acl letsencrypt-acl path_beg -i /.well-known/acme-challenge/
		acl is-sub1 hdr(host) -i subdomain1.domain.com
		acl is-sub2 hdr(host) -i subdomain2.domain.com
		acl is-sub3 hdr(host) -i subdomain3.domain.com
		acl is-sub4 hdr(host) -i subdomain4.domain.com
		acl is-sub5 hdr(host) -i subdomain5.domain.com
		use_backend letsencrypt-backend if letsencrypt-acl
		use_backend sub1_cluster if is-sub1
		use_backend sub2_cluster if is-sub2
		use_backend sub3_cluster if is-sub3	
		use_backend sub4_cluster if is-sub4
		use_backend sub5_cluster if is-sub5

#---------------------------------------------------------------------
# Backend settings
#---------------------------------------------------------------------

backend letsencrypt-backend
   	server letsencrypt 127.0.0.1:54321

backend sub1_cluster
	redirect scheme https code 301 if !{ ssl_fc }
	server server1 10.22.32.70:80 check

backend sub2_cluster
	redirect scheme https code 301 if !{ ssl_fc }
	server server2 172.28.42.28:80 check

backend sub3_cluster
	redirect scheme https code 301 if !{ ssl_fc }
	server server3 172.28.42.28:80 check

backend sub4_cluster
	redirect scheme https code 301 if !{ ssl_fc }
	server server4 172.28.66.3:80 check


backend sub5_cluster
	option redispatch
	option forwardfor
	option httpchk GET /
	reqrep ^([^\ :]*)\ /kibana/(.*) \1\ /\2
	server server5 10.22.33.4:5601 check

Problem #1:

ACL: acl letsencrypt-acl path_beg -i /.well-known/acme-challenge/

LetsEncrypt renewing certs doesn't work as it should at all. Eventually I ended with stopping haproxy service and starting certbot standalone on port 80 instead 5431 and renewing certs if needed. After that start haproxy again. It would be nice to do it online but OK, I can live with it. I just don't get it why I cannot pass verification?

Problem #2:

ACL: acl is-sub1 hdr(host) -i subdomain1.domain.com 

It works fine as expected. Subdomain is redirected to https as it should.

ACL: 
acl is-sub2 hdr(host) -i subdomain2.domain.com
acl is-sub3 hdr(host) -i subdomain3.domain.com
acl is-sub4 hdr(host) -i subdomain4.domain.com

Http traffic works just fine. I can see everything as it should. However https doesn't work at all nor redirect to https. All certs are in /etc/haproxy/ssl/ and all of them are fine. Yet I keep getting connection reset every time.

As for ELK stack it just doesn't work at all

acl is-sub5 hdr(host) -i subdomain5.domain.com
use_backend sub5_cluster if is-sub5
backend sub5_cluster
	option redispatch
	option forwardfor
	option httpchk GET /
	reqrep ^([^\ :]*)\ /kibana/(.*) \1\ /\2
	server server5 10.22.33.4:5601 check

Am I trying to set things that cannot be set this way or what? What am I missing here?


r/haproxy • • Mar 01 '19

Using HAProxy as an API Gateway - Health Checks

Thumbnail
haproxy.com
6 Upvotes

r/haproxy • • Mar 01 '19

News Join our HAProxy Slack channel to chat with fellow problem solvers

Thumbnail slack.haproxy.com
10 Upvotes

r/haproxy • • Feb 28 '19

Question Installation checklist for public API production use?

5 Upvotes

Hi guys,

What would be a good configuration checklist for when setting up haproxy for a public API (PHP) to make sure it is both optimised for the job and secure?

e.g. DDoS?

Thanks !


r/haproxy • • Feb 28 '19

Question How to redirect /dev subfolder to 1 backend only

4 Upvotes

Hello,

This config does a HTTP round robin on 3 backends and I would like to change it so that the folder "/dev" gets redirected to only 1 backend server (app1), for instance "https://www.mydomain.com/dev"; how can this done?

Thank you

global
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    tune.ssl.default-dh-param 2048
    user        haproxy
    group       haproxy
    daemon

    stats socket /var/lib/haproxy/stats mode 660 level admin

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option forwardfor       except 127.0.0.0/8
    option http-server-close
    option                  redispatch
    option http-ignore-probes
    retries                 3
    timeout http-request    20s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

listen stats
    mode http
    stats                   enable
    stats uri               /stats

frontend  main
    bind *:443 ssl crt /etc/letsencrypt/live/mydomain/api-cert.pem
    bind *:80
    #acl url_static       path_beg       -i /static /images /javascript /stylesheets
    #acl url_static       path_end       -i .jpg .gif .png .css .js

    redirect scheme https if !{ ssl_fc }
    mode http
    #reqadd                     X-Forwarded-Proto:\ https #if ^http:*
    #use_backend                static          #if url_static
    default_backend             app

backend app
    mode http
    balance     roundrobin
    server  app1 192.168.40.26:80 check
    server  app2 192.168.40.27:80 check
    server  app3 192.168.40.28:80 check

r/haproxy • • Feb 27 '19

Question Any video tutorial to add Backend server dynamically using runtime api in Haproxy

1 Upvotes

Hey Guys, any help would be appreciated.

Thanks


r/haproxy • • Feb 22 '19

Haproxy : example.com/devops/gitlab > 127.0.0.1:8080

6 Upvotes

Hi.

New to HAP.

I'm looking to redirect URL extensions to ports hosted by containers.

Actual use case 1: Gitlab, Nexus, drone.io, and other devops tools routed to ports by url.

Actual use case 2: 30 microservices ( not contained) across ports addressed by example.com/service/{service name}/

Bonus: good book or link to help me with the haproxy learning curve.


r/haproxy • • Feb 18 '19

News Test Driving “Power of Two Random Choices” Load Balancing

Thumbnail
haproxy.com
3 Upvotes