{"id":1166,"date":"2017-02-28T09:25:59","date_gmt":"2017-02-28T03:55:59","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1166"},"modified":"2026-09-11T17:00:47","modified_gmt":"2026-09-11T11:30:47","slug":"install-haproxy-configure-haproxy","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/install-haproxy-configure-haproxy\/","title":{"rendered":"How to Install and Configure HAProxy on Ubuntu"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">HAProxy is a high-performance load balancer and proxy that can be used to forward incoming requests to backend servers. It is useful when you need to route traffic from one server to another service or distribute traffic across multiple backend servers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, we will explain how to install HAProxy on an Ubuntu server and configure it to forward requests received on port <strong>8080<\/strong> to a backend server running on port <strong>8080<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding, ensure you have:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>An Ubuntu server with root or sudo access.<\/li>\n\n\n\n<li>A backend server running the required service.<\/li>\n\n\n\n<li>A custom service that can receive requests on port <strong>8080<\/strong>.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, requests received on port <strong>8080<\/strong> of the HAProxy server will be forwarded to another server at <code>xx.xx.xx.xx:8080<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Install HAProxy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Install HAProxy using the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apt-get install haproxy<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Start and Enable HAProxy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Start the HAProxy service:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl start haproxy<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable HAProxy to start automatically after a system reboot:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl enable haproxy<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, we will use the default HAProxy configuration and add a listener that forwards requests from port <strong>8080<\/strong> to the backend server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the HAProxy configuration file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi \/etc\/haproxy\/haproxy.cfg<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">listen nameapp 0.0.0.0:8080\n    mode http\n    balance roundrobin\n    server server1 xx.xx.xx.xx:8080 check<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above configuration listens for requests on port <strong>8080<\/strong> of the HAProxy server and forwards them to <code>xx.xx.xx.xx<\/code> on port <strong>8080<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuration Details<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>listen nameapp<\/strong> \u2013 Defines the HAProxy listener and gives it a name.<\/li>\n\n\n\n<li><strong>0.0.0.0:8080<\/strong> \u2013 HAProxy listens for incoming connections on port 8080 on all available interfaces.<\/li>\n\n\n\n<li><strong>mode http<\/strong> \u2013 Configures HAProxy to handle HTTP traffic.<\/li>\n\n\n\n<li><strong>balance roundrobin<\/strong> \u2013 Distributes traffic between multiple backend servers using the round-robin method when multiple servers are configured.<\/li>\n\n\n\n<li><strong>server server1<\/strong> \u2013 Defines the backend server to which the requests are forwarded.<\/li>\n\n\n\n<li><strong>check<\/strong> \u2013 Enables health checking of the backend server.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If multiple backend servers are added, HAProxy can distribute incoming traffic between them using the configured load-balancing method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Restart HAProxy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Restart the HAProxy service to apply the configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl restart haproxy<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Verification<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Access the HAProxy server using port <strong>8080<\/strong> from a browser:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">http:\/\/&lt;HaproxyIPaddress>:8080<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The request should be forwarded to the configured backend server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">HAProxy can be used to efficiently forward incoming requests to backend services and distribute traffic across multiple servers. In this example, HAProxy was installed on Ubuntu and configured to forward port <strong>8080<\/strong> requests to a backend server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This basic configuration can also be extended by adding multiple backend servers and using HAProxy&#8217;s load-balancing capabilities.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is HAProxy used for?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">HAProxy is commonly used as a load balancer and proxy to route incoming traffic to backend servers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Which configuration file is used by HAProxy?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The default HAProxy configuration file is:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/etc\/haproxy\/haproxy.cfg<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. How can I restart HAProxy after changing the configuration?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl restart haproxy<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. Can HAProxy forward traffic to multiple servers?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Multiple backend servers can be added to the configuration, and HAProxy can distribute traffic between them using a load-balancing method such as <code>roundrobin<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. How can I verify that HAProxy is working?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Access the HAProxy server using its IP address and configured port, for example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">http:\/\/&lt;HaproxyIPaddress>:8080<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the configuration is working correctly, the request will be routed to the backend server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-lock-and-unlock-a-user-on-ubuntu-24-04\/\">How to Lock and Unlock a User on Ubuntu 24.04?<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/liquibase-installation-on-ubuntu-24\/\">Liquibase Installation on Ubuntu 24<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Have a technology challenge or are you looking for the right solution for your business? Our team can help you with <strong>cloud, DevOps, development, infrastructure, design, and more<\/strong>. Feel free to reach out to our experts <a href=\"https:\/\/pheonixsolutions.com\/contact\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction HAProxy is a high-performance load balancer and proxy that can be used to forward incoming requests to backend servers. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[288,274],"class_list":["post-1166","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-haproxy","tag-ubuntu","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-iO","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1166"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1166\/revisions"}],"predecessor-version":[{"id":11665,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1166\/revisions\/11665"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}