
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
该Docker镜像旨在替换HTTP服务器或K8S集群的标准错误页面,提供更具原创性和吸引力的替代方案。包含以下核心组件:Go语言编写的错误页面生成器、多种设计风格的单页错误模板(主题)、轻量级HTTP服务器(独立二进制文件或Docker镜像形式提供)以及预生成的错误页面资源。
Content-Type或X-Format请求头返回对应格式响应(支持json、xml、plaintext)/healthz,支持服务状态监控| 镜像仓库 | 镜像地址 |
|---|---|
| GitHub Container Registry (GHCR) | ghcr.io/tarampampam/error-pages |
| Docker Hub(镜像) | tarampampam/error-pages |
[!重要] 强烈不建议使用
latest标签,因为主版本升级可能包含不兼容变更。请使用X.Y.Z格式的具体版本标签。
从https://github.com/tarampampam/error-pages/releases/latest%E4%B8%8B%E8%BD%BD%E5%AF%B9%E5%BA%94%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%9E%B6%E6%9E%84%E7%9A%84%E6%9C%80%E6%96%B0%E9%A2%84%E7%BC%96%E8%AF%91%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%96%87%E4%BB%B6%E3%80%82
可直接下载已渲染的错误页面压缩包:
以下模板已内置,无需额外配置即可使用:
| 模板名称 | 说明 |
|---|---|
app-down | 应用下线风格,简洁明了 |
cats | 猫咪图片风格(唯一依赖外部资源的模板,需联网加载图片) |
connection | 网络连接风格,带有连接状态可视化元素 |
ghost | 幽灵主题,深色背景与动态效果 |
hacker-terminal | 黑客终端风格,模拟命令行界面 |
l7 | L7风格,现代简约设计 |
lost-in-space | 太空迷失风格,科幻主题 |
noise | 噪点风格,复古颗粒感设计 |
orient | 东方风格,融合传统元素 |
shuffle | 随机风格,动态变化视觉效果 |
win98 | Windows 98风格,复古操作系统界面 |
[!注意]
cats模板会从外部服务器加载实际猫咪图片,其他模板均为自包含设计,不依赖外部资源。
二进制文件启动
bash./error-pages serve
Docker启动
bashdocker run --rm -p '8080:8080/tcp' docker.xuanyuan.run/tarampampam/error-pages serve
服务器默认监听0.0.0.0:8080,可通过http://127.0.0.1:8080/{状态码}.html访问错误页面(如http://127.0.0.1:8080/404.html)。
自定义错误状态码
通过X-Code HTTP头指定错误状态码,使用静态URL访问:
bashcurl -H 'X-Code: 500' http://127.0.0.1:8080/
配置选项
--template-name或环境变量TEMPLATE_NAME切换模板(如TEMPLATE_NAME=l7)--show-details或环境变量SHOW_DETAILS=true启用详细错误信息(含上游代理信息)--rotation-mode或环境变量TEMPLATES_ROTATION_MODE启用模板自动切换(支持random-on-startup/random-on-each-request/random-hourly/random-daily)my-super-theme.html:html<!DOCTYPE html> <html lang="zh-CN"> <head> <title>{{ code }} - 自定义错误页面</title> </head> <body> <h1>错误 {{ code }}: {{ message }}</h1> <p>{{ description }}</p> </body> </html>
bashdocker run --rm \ -v "$(pwd)/my-super-theme.html:/opt/my-template.html:ro" \ -p '8080:8080/tcp' \ ***-ghcr.xuanyuan.run/tarampampam/error-pages:3 serve \ --add-template /opt/my-template.html \ --template-name my-template
bashcurl -H "Accept: text/html" http://127.0.0.1:8080/503
使用自定义模板生成静态错误页面文件:
bash# 创建输出目录 mkdir -p /path/to/output # 生成错误页面 ./error-pages build \ --add-template /path/to/your/my-template.html \ --target-dir /path/to/output
生成的文件结构示例:
/path/to/output/ └── my-template ├── 400.html ├── 401.html ├── 403.html ├── 404.html ├── ...(其他状态码文件)
1. 创建Nginx配置文件nginx.conf:
nginxserver { listen 80; server_name localhost; # 配置错误页面映射 error_page 401 /_error-pages/401.html; error_page 403 /_error-pages/403.html; error_page 404 /_error-pages/404.html; error_page 500 /_error-pages/500.html; error_page 502 /_error-pages/502.html; error_page 503 /_error-pages/503.html; # 内部错误页面路径配置 location ^~ /_error-pages/ { internal; root /usr/share/nginx/errorpages; } # 主站点配置 location / { root /usr/share/nginx/html; index index.html index.htm; } }
2. 创建Dockerfile:
dockerfileFROM docker.xuanyuan.run/library/nginx:1.27-alpine # 覆盖默认Nginx配置 COPY --chown=nginx ./nginx.conf /etc/nginx/conf.d/default.conf # 从error-pages镜像复制预生成的错误页面(将ghost替换为其他模板名称) COPY --chown=nginx \ --from=ghcr.io/tarampampam/error-pages:3 \ /opt/html/ghost /usr/share/nginx/errorpages/_error-pages
3. 构建并测试镜像:
bash# 构建镜像 docker build --tag your-nginx:local -f ./Dockerfile . # 启动镜像 docker run --rm -p '8081:80/tcp' docker.xuanyuan.run/your-nginx:local # 测试错误页面(新终端) curl http://127.0.0.1:8081/不存在的路径
创建compose.yml文件:
yamlservices: traefik: image: docker.xuanyuan.run/library/traefik:v3.1 command: - --api.dashboard=true - --api.insecure=true - --providers.docker=true - --providers.docker.exposedbydefault=false - --entrypoints.web.address=:80 ports: - "80:80/tcp" volumes: - /var/run/docker.sock:/var/run/docker.sock:ro labels: traefik.enable: true traefik.http.routers.traefik.rule: Host(`traefik.localtest.me`) traefik.http.routers.traefik.service: api@internal traefik.http.routers.traefik.entrypoints: web traefik.http.routers.traefik.middlewares: error-pages-middleware depends_on: error-pages: {condition: service_healthy} error-pages: image: ***-ghcr.xuanyuan.run/tarampampam/error-pages:3 environment: TEMPLATE_NAME: l7 # 设置模板名称 labels: traefik.enable: true traefik.http.routers.error-pages-router.rule: HostRegexp(`.+`) traefik.http.routers.error-pages-router.priority: 10 traefik.http.routers.error-pages-router.entrypoints: web traefik.http.routers.error-pages-router.middlewares: error-pages-middleware # 错误中间件配置 traefik.http.middlewares.error-pages-middleware.errors.status: 400-599 traefik.http.middlewares.error-pages-middleware.errors.service: error-pages-service traefik.http.middlewares.error-pages-middleware.errors.query: /{status}.html traefik.http.services.error-pages-service.loadbalancer.server.port: 8080 # 测试服务(可选) nginx-or-any-another-service: image: docker.xuanyuan.run/library/nginx:1.27-alpine labels: traefik.enable: true traefik.http.routers.test-service.rule: Host(`test.localtest.me`) traefik.http.routers.test-service.entrypoints: web traefik.http.routers.test-service.middlewares: error-pages-middleware
启动服务:
bashdocker compose up
访问测试:
http://traefik.localtest.me/dashboard/http://test.localtest.me/不存在的路径通过Helm配置Ingress Nginx,添加以下参数至values.yaml:
yamlcontroller: config: custom-http-errors: >- 401,403,404,500,501,502,503 # 需处理的错误状态码 defaultBackend: enabled: true image: repository: ghcr.io/tarampampam/error-pages tag: '3' # 指定具体版本,不建议使用latest extraEnvs: - name: TEMPLATE_NAME # 可选:设置模板 value: l7 - name: SHOW_DETAILS # 可选:启用详细错误信息 value: 'true'
通过Helm部署错误页面服务及Traefik中间件,主要包含以下资源(示例模板):
1. 命名空间(namespace.yaml)
yamlapiVersion: v1 kind: Namespace metadata: name: error-pages
2. 部署(deployment.yaml)
yamlapiVersion: apps/v1 kind: Deployment metadata: name: error-pages namespace: error-pages labels: app: error-pages spec: replicas: 1 selector: matchLabels: app: error-pages template: metadata: labels: app: error-pages spec: automountServiceAccountToken: false containers: - name: error-pages image: ***-ghcr.xuanyuan.run/tarampampam/error-pages:3 env: - name: TEMPLATE_NAME value: shuffle # 设置模板 securityContext: runAsNonRoot: true runAsUser: 10001 runAsGroup: 10001 readOnlyRootFilesystem: true ports: - name: http containerPort: 8080 livenessProbe: httpGet: path: /healthz port: http readinessProbe: httpGet: path: /healthz port: http resources: limits: memory: 64Mi cpu: 200m requests: memory: 16Mi cpu: 20m
3. 服务(service.yaml)
yamlapiVersion: v1 kind: Service metadata: name: error-pages-service namespace: error-pages spec: type: ClusterIP selector: app: error-pages ports: - name: http port: 8080 targetPort: 8080
4. Traefik中间件(middleware.yaml)
yamlapiVersion: traefik.io/v1alpha1 kind: Middleware metadata: name: error-pages namespace: error-pages spec: errors: status: ["401", "403", "404", "500-599"] service: name: error-pages-service port: 8080 query: "/{status}.html"
应用上述资源后,在Traefik IngressRoute中引用中间件:
yamlapiVersion: traefik.io/v1alpha1 kind: IngressRoute metadata: name: example-app namespace: example spec: entryPoints: - websecure routes: - match: Host(`app.example.com`) kind: Rule services: - name: example-service port: 80 middlewares: - name: error-pages namespace: error-pages # 跨命名空间引用需Traefik开启allowCrossNamespace
注:Traefik需配置
--providers.kubernetescrd.allowCrossNamespace=true以支持跨命名空间中间件引用。
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务