How To Implement SSL With HAProxy on Debian

Generate the CSR and KEY SSL file:

cd /etc/ssl/private/
openssl req -nodes -newkey rsa:2048 -keyout myserver.key -out server.csr

Then sent the .csr file to your SSL Provider and get the .crt file and put on /etc/ssl.

Install the HAProxy last version

add-apt-repository ppa:vbernat/haproxy-1.7
apt-get update
apt-get install haproxy

HAProxy Configuration

Edit the file: /etc/haproxy/haproxy.cfg and adjusts the maxconn and increase this line bellow in the global section:

tune.ssl.default-dh-param 2048

In the default section, put this lines under the mode http:

option forwardfor
option http-server-close

This will add X-Forwarded-For headers to each request, as well as reduce the latency between HAProxy and to preserve client persistent connections.

At the proxy section:

frontend www-http
   bind $PUBLIC_IP:80
   reqadd X-Forwarded-Proto:\ http
   default_backend www-backend

frontend www-https
   bind $PUBLIC_IP:443 ssl crt /etc/ssl/private/myserver.crt
   reqadd X-Forwarded-Proto:\ https
   default_backend www-backend

backend www-backend
   redirect scheme https if !{ ssl_fc }
   server host1 $PRIVATE_IP:80 check
   server host2 $PRIVATE_IP:80 check

Restart the HAProxy

sudo service haproxy restart

Find how much Ram the Apache is using per process

Find how much Ram the Apache is using per process

The best tool I’ve found to do that is:

The output of ps_mem is:

 Private  +   Shared  =  RAM used	Program

  7.8 MiB +   1.6 MiB =   9.4 MiB	bash (4)
 39.7 MiB +  34.8 MiB =  74.5 MiB	apache2 (76)
287.7 MiB + 411.5 KiB = 288.1 MiB	mysqld
                        451.2 MiB

Here you can see 76 process of apache2 using 74.5 MiB, so to calc that is really easy, 1 process memory usage = RAM used / number of process, using the values from this example above will be 74,5 / 76 = 0,98 MiB.