Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › DevOps

How to Set a Custom 503 Error Page in HAProxy

By Freedom251 Team · · 10 min read

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To customize a 503 generated by HAProxy, put a complete HTTP response in a local file, map status 503 to that file in a named http-errors section, and attach the section to the frontend (or another proxy section) with errorfiles. Validate the configuration and reload HAProxy after every file change: HAProxy reads error files at configuration load and keeps them in memory.

This changes HAProxy’s own 503 response. It does not automatically replace a 503 body sent by your application backend; that requires an explicit response rule.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a custom HAProxy 503 page actually changes

HTTP status 503 means “Service Unavailable.” HAProxy can generate that response when it cannot select a usable backend server, all servers are down, a connection cannot be established, or another proxy-level condition prevents forwarding the request. In those cases, HAProxy can serve a locally defined response instead of its built-in error page.

There are two different 503 origins to keep separate:

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
  • HAProxy-generated 503: the load balancer creates the status because it cannot complete the request. An errorfile 503 mapping applies here.
  • Backend-generated 503: an application server receives the request and returns status 503 itself. HAProxy normally forwards that response unchanged. An errorfile mapping alone does not replace it.

The distinction determines which configuration you need. Start with a static error file for proxy-generated failures. Add response interception only if you intentionally want to replace application responses too.

Minimal configuration for a static 503 page

The smallest reusable configuration has three parts: a named error group, an errorfile entry for status 503, and an errorfiles reference in the frontend that can emit the error.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# /etc/haproxy/haproxy.cfg
http-errors myerrors
    errorfile 503 /etc/haproxy/errorfiles/503.http

frontend www
    bind :80
    default_backend webservers
    errorfiles myerrors

The path should be absolute. The file name does not have to end in .http, but that suffix is recommended because it makes the file’s purpose obvious. The named group can be attached to more than one frontend when the same response should be reused.

The errorfiles directive belongs in the proxy section whose errors you want to customize. For a normal HTTP site, that is commonly a frontend. If you have separate frontends, each one needs its own reference unless it inherits the setting through another supported configuration arrangement.

Build the complete response file

An HAProxy errorfile is not just an HTML fragment. It must contain a complete HTTP response: a status line, response headers, one empty line, and the body.

HTTP/1.1 503 Service Unavailable
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8

<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Temporarily unavailable</title></head>
<body>
  <h1>Service temporarily unavailable</h1>
  <p>Please try again shortly.</p>
</body>
</html>

Status line

HTTP/1.1 503 Service Unavailable identifies the protocol version, numeric status, and reason phrase. Keep the numeric status at 503 so monitoring systems, clients, and caches receive the intended result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Headers

Content-Type: text/html; charset=utf-8 tells browsers to render the body as UTF-8 HTML. Cache-Control: no-cache prevents a temporary outage page from being treated as a long-lived success or failure document by intermediaries that honor that directive. Add other headers only when you understand their effect; the response file is sent as the response HAProxy generates.

Body and separator

The blank line between headers and HTML is required HTTP syntax. Keep the HTML self-contained if the page must work while every backend is unavailable. References to an unavailable application, a private network path, or a separate asset host can make the page appear broken during the exact outage it is meant to explain.

Step-by-step installation

  1. Create a dedicated directory. For example, create /etc/haproxy/errorfiles using the account or deployment method appropriate to your operating system.
  2. Write the response file. Save the complete response as /etc/haproxy/errorfiles/503.http. Preserve the header/body blank line and use valid HTML if you are serving an HTML page.
  3. Set readable permissions. The HAProxy process must be able to read the file when it loads its configuration. If the service is chrooted, the path must also be available inside the configured chroot. Avoid making the file writable by an untrusted account.
  4. Add the error group. In the global configuration file, add http-errors myerrors followed by an indented errorfile 503 line with the absolute path.
  5. Attach the group. Add errorfiles myerrors to the frontend or other proxy section whose HAProxy-generated 503 responses should use the file.
  6. Validate before applying. Run the configuration parser for the installed version, such as haproxy -c -f /etc/haproxy/haproxy.cfg. Treat any warning or error as a deployment failure until it is understood.
  7. Reload HAProxy. Use the reload mechanism supplied by your service manager or package. There is no single universal command because distributions and service layouts differ. A restart is not inherently required, but the running process must load the new configuration and file.
  8. Test a controlled failure. Make a backend unavailable in a maintenance window or use a test frontend whose backend has no available servers. Confirm the status, headers, and body with a browser and an HTTP client.

Do not edit the file and expect an already running process to notice it. HAProxy reads and stores custom error files in memory at the same time it reads the configuration. Every content change therefore requires another successful load and reload.

How to verify the result safely

Testing a normal healthy request proves only that the frontend works; it does not prove the 503 path. Use an isolated test listener or a maintenance backend whenever possible.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the wire response

Request the affected listener with a client that displays headers and the body, for example:

curl -i http://your-test-host/

When HAProxy itself produces the failure, the response should have status 503, the headers from your file, and the HTML or text body you supplied. Check the actual response rather than relying on a browser cache or a page previously loaded through a different frontend.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord | 6.35mm Jack, Durable Design, Stage and Home Studio Use, Low Noise Shielded Electric Cord for Bass, Keyboard, Amp, Mixer
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Confirm which component generated the status

Inspect HAProxy logs and the backend’s logs for the same request. If the application logged and returned the request, you are testing a backend-generated 503, so the basic errorfile mapping is not expected to change its body. If no backend handled the request and HAProxy reports that no server was available, the local error file is the relevant path.

Test after every deployment change

Validate the configuration before reload, then repeat the controlled request after reload. A successful parser check confirms syntax and file loading, while the HTTP request confirms that the intended frontend actually references the error group.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why an edited page does not appear until reload

The most common explanation is HAProxy’s load-time behavior. The process reads the error file and stores its contents in memory while loading the configuration. Updating 503.http on disk changes nothing for existing workers until a new configuration load occurs.

  • Confirm that you edited the exact absolute path in the active configuration.
  • Run the version-appropriate configuration check after the edit.
  • Reload the service through its service manager and verify that the reload succeeded.
  • Send a request that reaches the same frontend; a different listener may use another errorfiles group.
  • Use a cache-bypassing client during testing. The response file’s Cache-Control: no-cache header helps, but an intermediary can still have its own behavior.

If the reload fails, the old process may continue serving the previous page. Check the service manager’s status and logs rather than assuming the file was accepted.

Replacing a 503 returned by the backend

To replace an application’s 503 body, define the error group as usual and add an http-response return rule conditioned on the response status.

http-errors myerrors
    errorfile 503 /etc/haproxy/errorfiles/503.http

frontend www
    bind :80
    default_backend webservers
    errorfiles myerrors
    http-response return status 503 default-errorfiles if { status 503 }

This rule examines the response and returns status 503 using the selected default error files when the backend response status is 503. It replaces the backend’s response body and headers for matching responses. That is deliberately broader than customizing HAProxy’s own outage page: application-specific diagnostics, headers, or retry instructions can be lost.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

When interception is appropriate

  • Use it when every 503 presented to clients must have one consistent maintenance design.
  • Use it when backend services expose internal details that should not reach users.
  • Avoid it when different applications need distinct 503 bodies or headers.
  • Avoid it when the backend’s 503 includes meaningful machine-readable data that clients depend on, unless you reproduce that contract.

Test both failure paths separately. A backend outage that prevents connection and an application that deliberately returns 503 exercise different HAProxy behavior.

Redirecting instead of serving a local file

HAProxy can redirect an HAProxy-generated 503 with errorloc 503 <url>. The errorloc and errorloc302 forms document 302 behavior, while errorloc303 returns 303 See Other. A 303 instructs clients to fetch the destination with GET, which is generally safer when the original request was not a GET, such as a form submission.

Redirecting changes the client-visible behavior: the client receives a second request rather than the original local response body. Ensure the destination is available independently of the failed backend. A relative URL must not point to a resource that can produce the same error, or the client can enter a redirect loop.

These directives apply to errors generated by HAProxy. They do not rewrite a 503 that originated in the backend application; use an explicit http-response rule if that is required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Static files versus dynamic error responses

A static errorfile is the simplest and most predictable option. For template-driven responses, HAProxy’s http-error directive supports lf-file and lf-string forms that can render sample-fetch expressions.

file and lf-file are not interchangeable

The tutorial syntax distinguishes lf-file, which renders content as a log-format template, from file, which serves raw content. Choose lf-file only when you need HAProxy to evaluate supported sample-fetch expressions. If the file should be delivered literally, use the raw form instead.

Set the content type for templates

When returning a template directly, set an appropriate content-type. Without an explicit type, clients may not interpret the generated body as intended. Keep expressions limited to values that are safe to expose; an outage page should not leak request data, internal addresses, or sensitive headers.

Dynamic forms are useful for a small amount of request-aware text, but they add syntax and validation complexity. For a branded page that never changes per request, a static full response is easier to review and less likely to fail during an outage.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choosing an implementation

Approach Best for Response behavior Main caveat
Static errorfile 503 HAProxy-generated 503s with one fixed page Serves a complete local HTTP response Requires a reload after file edits
http-response return on status 503 Replacing backend-generated 503s Returns the selected HAProxy error response Overwrites backend body and headers
errorloc 503 or errorloc302 Redirecting clients to another URL Uses documented 302 redirect behavior Destination availability and loops must be managed
errorloc303 Redirecting non-GET requests safely Uses 303 so the follow-up request is GET Still depends on an independent destination
http-error with lf-file or lf-string Template-driven or request-aware content Renders log-format expressions More syntax and exposure considerations than static files

Version, size and compatibility limits

The documented http-errors approach applies to HAProxy 2.1 and newer, along with corresponding Enterprise and ALOHA versions. Directive availability and the list of customizable statuses can vary by release, so check the manual for the exact version deployed on each server.

Error files are parsed during configuration loading and retained in memory. The response must fit the configured response buffer. A malformed response can fail configuration validation; an oversized response can fail validation or serving. Keep the page compact, remove unnecessary inline assets, and test the real file on the real HAProxy build before relying on it for production maintenance.

Mixed-version fleets deserve special care. A configuration accepted on one node may use a directive unavailable on an older node. Validate on every version that will receive the configuration, and roll out in a way that preserves a working listener if a node rejects the new file.

Troubleshooting checklist

Symptom Likely cause What to check
Built-in HAProxy page still appears The error group is not attached to the active frontend, or the process was not reloaded Confirm errorfiles myerrors, the active configuration path, reload status, and the frontend receiving the request
Old custom page appears The file was edited after configuration load Validate and reload; HAProxy keeps loaded content in memory
Application 503 is unchanged The status came from the backend Inspect logs and add a deliberate http-response return rule if replacement is intended
Configuration check fails Malformed response, unsupported directive, bad path, or unreadable file Check the exact HAProxy version, absolute path, permissions, response syntax, and file size
Page is blank or garbled Missing header/body separator, incorrect content type, or truncated response Inspect the raw file and the raw HTTP response with a header-displaying client
Redirect repeats indefinitely The redirect target reaches the same failing path Use an independently available destination and avoid a relative URL that maps back to the failing resource

Operational practices for dependable outage pages

  • Keep the file self-contained. Inline the minimal CSS needed for readability so the page does not depend on a failed application or asset server.
  • Review status and headers together. A page that looks correct in a browser can still return the wrong status or omit a required content type.
  • Use a reusable group carefully. Sharing one named http-errors group reduces duplication, but a change then affects every attached frontend after reload.
  • Deploy atomically. Write and validate a complete replacement before reloading, rather than leaving a partially written file at the moment HAProxy reads it.
  • Protect the file. Permit the HAProxy process to read it while preventing unauthorized edits that could alter every client-facing outage response.
  • Test maintenance conditions. Include at least one test where no backend server is available and, if interception is configured, one where the backend deliberately returns 503.
  • Preserve observability. A customized body should not prevent normal HAProxy logging and status monitoring. Alert on the 503 status, not on the text of the page.

Practical decision sequence

  1. Determine whether HAProxy or the backend is producing status 503.
  2. For an HAProxy-generated response, choose a static errorfile unless you genuinely need templating or redirection.
  3. For a backend-generated response, decide whether replacing its body and headers is acceptable before adding interception.
  4. Use an absolute path, a complete HTTP response, and permissions readable by the HAProxy process.
  5. Validate with the parser for the deployed version, reload, and exercise the exact frontend and failure mode.
  6. Check the raw status, headers, and body, then document which reload mechanism and test scenario your operations team should use next time.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

DevOpsHAProxyHTTP 503load balancingWeb server configuration

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.