使用 Cloudflare 错误页面显示所有应用程序错误。
Show all your application error using Cloudflare Error Page

原始链接: https://github.com/donlon/cloudflare-error-page

## Cloudflare 错误页面生成器 概要 该项目允许您创建定制的错误页面,外观与 Cloudflare 使用的错误页面非常相似,并易于嵌入到您自己的网站中。 提供了在线编辑器,方便快速创建页面。 对于开发者,该项目可以通过 pip 安装 (`pip install git+https://github.com/donlon/cloudflare-error-page.git`),并使用 `render` 函数根据提供的参数生成 HTML 错误页面——控制浏览器、Cloudflare 和主机服务器的状态指示器。 **最新更新 (2025年12月9日):** 所有图标现在都是基于向量的,并与样式表内联到一个文件中,从而提高了性能并简化了部署,消除了外部资源依赖。 该项目支持通过 `ray_id` 和 `client_ip` 参数显示真实的细节,例如 Cloudflare Ray ID 和用户 IP。 提供了示例配置和 Flask 演示服务器 (`flask_demo.py`),以说明各种错误场景和自定义选项。 还有一个在线演示。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 展示你使用 Cloudflare 错误页面 (github.com/donlon) 的应用程序错误 6 分,由 sawirricardo 1 小时前发布 | 隐藏 | 过去 | 收藏 | 2 条评论 hk1337 26 分钟前 [–] 你能真正自定义那个 Cloudflare 错误页面吗? 我以为那是当他们与你的网站失去连接时的错误页面,自定义错误页面只是你的应用程序创建的,比如 404、403 等?回复 zamadatix 16 分钟前 | 父级 [–] 我认为本意是用于恶作剧页面,比如演示链接,它表现得像错误 500,说主机着火了等等,但实际上是 200 OK,而不是你实际的 Cloudflare 服务错误。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

📢 Update (2025/12/09): All icons used in the error page have been fully redrawn as vector assets. These icons along with the stylesheet are also inlined into a single file of the error page, eliminating any need of hosting additional resources and ensuring better experience for you and your end users.

What does this project do?

This project creates customized error pages that mimics the well-known Cloudflare error page. You can also embed it into your website.

Here's an online editor to create customized error pages. Try it out here.

Editor

(And thank @rynzland for the idea!)

Quickstart for Programmers

Install cloudflare-error-page with pip.

pip install git+https://github.com/donlon/cloudflare-error-page.git

Then you can generate an error page with the render function. (example.py)

import webbrowser
from cloudflare_error_page import render as render_cf_error_page

# This function renders an error page based on the input parameters
error_page = render_cf_error_page({
    # Browser status is ok
    'browser_status': {
        "status": 'ok',
    },
    # Cloudflare status is error
    'cloudflare_status': {
        "status": 'error',
        "status_text": 'Error',
    },
    # Host status is also ok
    'host_status': {
        "status": 'ok',
        "location": 'example.com',
    },
    # can be 'browser', 'cloudflare', or 'host'
    'error_source': 'cloudflare',

    # Texts shown in the bottom of the page
    'what_happened': '<p>There is an internal server error on Cloudflare\'s network.</p>',
    'what_can_i_do': '<p>Please try again in a few minutes.</p>',
})

with open('error.html', 'w') as f:
    f.write(error_page)

webbrowser.open('error.html')

Default error page

You can also see live demo here.

A demo server using Flask is also available in flask_demo.py.

Catastrophic infrastructure failure

params = {
    "title": "Catastrophic infrastructure failure",
    "more_information": {
        "for": "no information",
    },
    "browser_status": {
        "status": "error",
        "status_text": "Out of Memory",
    },
    "cloudflare_status": {
        "status": "error",
        "location": "Everywhere",
        "status_text": "Error",
    },
    "host_status": {
        "status": "error",
        "location": "example.com",
        "status_text": "On Fire",
    },
    "error_source": "cloudflare",
    "what_happened": "<p>There is a catastrophic failure.</p>",
    "what_can_i_do": "<p>Please try again in a few years.</p>",
}

Catastrophic infrastructure failure

Demo

params = {
    "title": "Web server is working",
    "error_code": 200,
    "more_information": {
        "hidden": True,
    },
    "browser_status": {
        "status": "ok",
        "status_text": "Seems Working",
    },
    "cloudflare_status": {
        "status": "ok",
        "status_text": "Often Working",
    },
    "host_status": {
        "status": "ok",
        "location": "example.com",
        "status_text": "Almost Working",
    },
    "error_source": "host",
    "what_happened": "<p>This site is still working. And it looks great.</p>",
    "what_can_i_do": "<p>Visit the site before it crashes someday.</p>",
}

Web server is working

Demo

How to show real user IP / Cloudflare Ray ID / data center location in the error page so that it looks more realistic?

Ray ID and user IP field in the error page can be set by ray_id and client_ip properties in the params argument passed to the render function. The real Cloudflare Ray ID and the data center location of current request can be extracted from the Cf-Ray request header (e.g. Cf-Ray: 230b030023ae2822-SJC). Detailed description of this header can be found in Cloudflare documentation.

To lookup the city name of the data center corresponding to the three letter code in the header, you can use a location list from here

The demo server runs in our website did handle these. Take a look at this file for reference.

{
    "html_title": "cloudflare.com | 500: Internal server error",
    "title": "Internal server error",
    "error_code": 500,
    "time": "2025-11-18 12:34:56 UTC",  // if not set, current UTC time is shown

    // Configuration for "Visit ... for more information" line
    "more_information": {
        "hidden": false,
        "text": "cloudflare.com", 
        "link": "https://www.cloudflare.com/",
        "for": "more information",
    },

    // Configuration for the Browser/Cloudflare/Host status
    "browser_status": {
        "status": "ok", // "ok" or "error"
        "location": "You",
        "name": "Browser",
        "status_text": "Working",
        "status_text_color": "#9bca3e",
    },
    "cloudflare_status": {
        "status": "error",
        "location": "Cloud",
        "name": "Cloudflare",
        "status_text": "Error",
        "status_text_color": "#bd2426",
    },
    "host_status": {
        "status": "ok",
        "location": "The Site",
        "name": "Host",
        "status_text": "Working",
        "status_text_color": "#9bca3e",
    },
    "error_source": "host", // Position of the error indicator, can be "browser", "cloudflare", or "host"

    "what_happened": "<p>There is an internal server error on Cloudflare's network.</p>",
    "what_can_i_do": "<p>Please try again in a few minutes.</p>",

    "ray_id": '0123456789abcdef',  // if not set, random hex string is shown
    "client_ip": '1.1.1.1',

    // Configuration for 'Performance & security by ...' in the footer
    "perf_sec_by": {
        "text": "Cloudflare",
        "link": "https://www.cloudflare.com/",
    },
}
联系我们 contact @ memedata.com