Using Varnish and HAProxy on the same server

July 11, 2014 2k views

Hi there,
I have Apache2 and Varnish on the same server, and I want to protect better my server against DDOS attacks. For this, I found HAProxy, and I would like to know if its a god idea to put Varnish and HAProxy on the same server ?
I have 2Gb ram and 4 cores

3 Answers

I've never used Varnish myself but you certainly can run both on the same server. To do that, you need to free up port 80 for HAProxy and bind Varnish to another port.

Edit /etc/default/varnish and replace DAEMON_OPTS="-a :80 \ with DAEMON_OPTS="-a :8080 \. If Apache2 is listening on port 8080, you can configure Varnish to listen on another port such as 8888 or whatever port you like.

Then, install HAProxy and configure it to listen on port 80 and reverse proxy connections to where 8080 is the port that Varnish is listening on.

Keep in mind that HAProxy isn't designed to protect from DDoS attacks but it can be configured to help in doing so.

Thank you so much for your response Kamal.
I have one more question, do you think that will slow down my website to put 2 reverses proxy in front of my website ?

  • Processing requests through an additional program will obviously cause more resource usage but the performance drop will most likely be negligible.

Have another answer? Share your knowledge.