• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, May 31, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Debian

Installing HAProxy 1.7 on Debian 9.1 (Stretch)

How VPS by How VPS
November 1, 2019
in Debian
0
0
SHARES
37
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Using a Different System?
  2. Requirements
  3. Installing HAProxy
  4. Configuring HAProxy
    1. Global Section
    2. Proxies Section
      1. Frontend Configuration
      2. Backend Configuration
    3. Debugging Errors
  5. Want to contribute?

Using a Different System?

  • Installing HAProxy on Ubuntu 14.04

Are we missing a guide for your target system? Request one, or submit your own!


HAProxy is a network software application that offers high availability, load balancing, and proxying for TCP and HTTP network applications. It is suited for high traffic websites, and powers many popular sites across the web. This article will show you how to install and configure HAProxy on Debian 9.1.

Although HAProxy has several prominent features, this article focuses on how to setup HAProxy to “proxy” your web application.

Requirements

  • At least two Vultr servers (for load balancing functionality) with your website or web application deployed to both of them.

Installing HAProxy

Debian 9 already ships with HAProxy 1.7 (latest stable release at time of writing), and we can simply install it using apt-get:

# apt-get update
# apt-get install haproxy

If the previous commands were successful, then you have installed HAProxy and you can proceed to the next step.

Configuring HAProxy

The HAProxy configuration file is split up into two sections — “global” and “proxies”. One deals with process-wide configuration, while the latter consists of default configuration, frontend, and backend sections.

Global Section

Using your favorite text editor, open /etc/haproxy/haproxy.cfg and notice the predefined sections: “global” and “defaults”. The first thing that you may want to do is increase the maxconn to a reasonable size, as this affects the connections that HAProxy allows. Too many connections may cause your web service to crash due to many requests. You will need to adjust the size to see what works for you. In the global section, we have chosen a maxconn value of 3072.

global
    daemon
    maxconn 3072

In the default section, add the following line under mode http:

option forwardfor

This will add X-Forwarded-For headers to each request, which allows your backend servers to learn the original IP address of the user.

Also, add this line to enable HTTP connection-close mode on the server side while keeping the ability to support HTTP keep-alive on the client side. This reduces latency on the client side and helps conserve server resources:

option http-server-close

If you wish to use keep-alive on both the client and server sides, then you could use option http-keep-alive instead. This option is particularly useful when the cost of establishing a new connection to the server is significant compared to the cost of retrieving the requested resource.

Finally, the resulting config file will look something like this:

defaults
    mode http
    option forwardfor
    option http-server-close
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

Proxies Section

To set up your proxy, you will need to add two sections to the configuration file to define the two parts of the proxy: the frontend and the backend.

Frontend Configuration

The frontend will handle your HTTP connections. Add the following to the end of your haproxy.cfg file:

frontend http-frontend
    bind public_ip:80
    reqadd X-Forwarded-Proto:/ http
    default_backend wwwbackend

Be sure to replace public_ip with your server’s public IP address or domain name.

Backend Configuration

Setup your backend by adding the following lines to the end of your configuration file:

backend wwwbackend
    server 1-www server1_ip:80 check
    server 2-www server2_ip:80 check
    server 3-www server3_ip:80 check

The backend configuration used here creates 3 connections named X-www. (X is 1, 2 or 3.) Each one of them corresponds to a serverX_ip:80 address. (Replace serverX_ip with your Vultr instances’ IP addresses.) This will allow you to load balance between each server in the specified server set (assuming each IP address corresponds to a different server). The check option makes the load balancer perform health checks on the server.

Save the configuration file, and then restart HAProxy:

service haproxy restart

If everything is working, then you will be able to connect to http://public_ip/ (replacing it with your public IP or domain name as configured in the frontend step) and view your website.

Debugging Errors

If your HAProxy instance refuses to start after your modifications, chances are that you have an error somewhere in the configuration file. To get clear messages about the issue in the configuration file, you can try to start HAProxy manually using this command:

# haproxy -f /etc/haproxy/haproxy.cfg

For instance, if you see output like this:

[ALERT] 234/195612 (2561) : parsing [/etc/haproxy/haproxy.cfg:48] : server 1-www has neither service port nor check port nor tcp_check rule 'connect' with port information. Check has been disabled.
[ALERT] 234/195612 (2561) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
[ALERT] 234/195612 (2561) : Fatal errors found in configuration.

Then, you have forgotten to specify the port number for the server 1-www.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

How to Install Mailtrain Newsletter Application on Debian 9

Next Post

How to Install Rocket.Chat on Debian 9

Next Post

How to Install Rocket.Chat on Debian 9

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet