{"id":26550149,"url":"https://github.com/mikyll/apisix-plugin-error-page","last_synced_at":"2025-07-07T06:38:41.177Z","repository":{"id":282436339,"uuid":"947879250","full_name":"mikyll/apisix-plugin-error-page","owner":"mikyll","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-14T16:18:59.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T16:41:03.776Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikyll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-13T11:46:59.000Z","updated_at":"2025-03-14T16:19:02.000Z","dependencies_parsed_at":"2025-03-14T16:41:09.082Z","dependency_job_id":"f843004f-e82d-4974-82bb-3a72dcb4c758","html_url":"https://github.com/mikyll/apisix-plugin-error-page","commit_stats":null,"previous_names":["mikyll/apisix-plugin-error-page"],"tags_count":0,"template":false,"template_full_name":"mikyll/apisix-plugin-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikyll%2Fapisix-plugin-error-page","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikyll%2Fapisix-plugin-error-page/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikyll%2Fapisix-plugin-error-page/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikyll%2Fapisix-plugin-error-page/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikyll","download_url":"https://codeload.github.com/mikyll/apisix-plugin-error-page/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244924714,"owners_count":20532872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-22T07:30:30.982Z","updated_at":"2025-07-07T06:38:41.171Z","avatar_url":"https://github.com/mikyll.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n[![APISIX][apisix-shield]][apisix-url]\n[![NGINX][nginx-shield]][nginx-url]\n[![Lua][lua-shield]][lua-url]\n[![Perl][perl-shield]][perl-url]\n[![YAML][yaml-shield]][yaml-url]\\\n[![Build Status][build-status-shield]][build-status-url]\n\n# APISIX Plugin error-page\n\nThis custom plugin allows APISIX to return a custom error page for status codes `404`, `500`, `502` and `503`.\n\nFor example, it allows to replace the default response for 404:\n\n```json\n{\"error_msg\":\"404 Route Not Found\"}\n```\n\n\u003c/div\u003e\n\n## Table of Contents\n\n- [APISIX Plugin error-page](#apisix-plugin-error-page)\n  - [Table of Contents](#table-of-contents)\n  - [Plugin Usage](#plugin-usage)\n    - [Installation](#installation)\n    - [Configuration](#configuration)\n      - [Plugin Metadata](#plugin-metadata)\n    - [Enable Plugin](#enable-plugin)\n      - [Traditional](#traditional)\n      - [Standalone](#standalone)\n    - [Example Usage](#example-usage)\n  - [Examples](#examples)\n    - [Standalone Example](#standalone-example)\n      - [Setup](#setup)\n      - [Test Routes](#test-routes)\n  - [Learn More](#learn-more)\n\n## Plugin Usage\n\n### Installation\n\nTo install custom plugins in APISIX there are 2 methods:\n\n- placing them alongside other built-in plugins, in `${APISIX_INSTALL_DIRECTORY}/apisix/plugins/` (by default `/usr/local/apisix/apisix/plugins/`);\n- placing them in a custom directory and setting `apisix.extra_lua_path` to point that directory, in `config.yaml`.\n\n[Back to TOC](#table-of-contents)\n\n### Configuration\n\nThis plugin can be configured for [Routes](https://apisix.apache.org/docs/apisix/terminology/route/) or [Global Rules](https://apisix.apache.org/docs/apisix/terminology/global-rule/).\n\n#### Plugin Metadata\n\n| Name                   | Type    | Required | Default                                                                                                                                                       | Valid values | Description                                                |\n| ---------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------------------------------------------------------- |\n| enable                 | boolean | False    | `false`                                                                                                                                                       |              | If true, enable the plugin.                                |\n| error_404              | object  | False    |                                                                                                                                                               |              | Error page to return when APISIX returns 404 status codes. |\n| error_404.body         | string  | False    | `\u003chtml\u003e \u003chead\u003e\u003ctitle\u003e404 Not Found\u003c/title\u003e\u003c/head\u003e \u003cbody\u003e \u003ccenter\u003e\u003ch1\u003e404 Not Found\u003c/h1\u003e\u003c/center\u003e \u003chr\u003e\u003ccenter\u003eAPISIX\u003c/center\u003e \u003c/html\u003e`                         |              | Response body.                                             |\n| error_404.content-type | string  | False    | `text/html`                                                                                                                                                   |              | Response content type.                                     |\n| error_500              | object  | False    |                                                                                                                                                               |              | Error page to return when APISIX returns 500 status codes. |\n| error_500.body         | string  | False    | `\u003chtml\u003e \u003chead\u003e\u003ctitle\u003e500 Internal Server Error\u003c/title\u003e\u003c/head\u003e \u003cbody\u003e \u003ccenter\u003e\u003ch1\u003e500 Internal Server Error\u003c/h1\u003e\u003c/center\u003e \u003chr\u003e\u003ccenter\u003eAPISIX\u003c/center\u003e \u003c/html\u003e` |              | Response body.                                             |\n| error_500.content-type | string  | False    | `text/html`                                                                                                                                                   |              | Response content type.                                     |\n| error_502              | object  | False    |                                                                                                                                                               |              | Error page to return when APISIX returns 502 status codes. |\n| error_502.body         | string  | False    | `\u003chtml\u003e \u003chead\u003e\u003ctitle\u003e502 Bad Gateway\u003c/title\u003e\u003c/head\u003e \u003cbody\u003e \u003ccenter\u003e\u003ch1\u003e502 Bad Gateway\u003c/h1\u003e\u003c/center\u003e \u003chr\u003e\u003ccenter\u003eAPISIX\u003c/center\u003e \u003c/html\u003e`                     |              | Response body.                                             |\n| error_502.content-type | string  | False    | `text/html`                                                                                                                                                   |              | Response content type.                                     |\n| error_503              | object  | False    |                                                                                                                                                               |              | Error page to return when APISIX returns 503 status codes. |\n| error_503.body         | string  | False    | `\u003chtml\u003e \u003chead\u003e\u003ctitle\u003e503 Service Unavailable\u003c/title\u003e\u003c/head\u003e \u003cbody\u003e \u003ccenter\u003e\u003ch1\u003e503 Service Unavailable\u003c/h1\u003e\u003c/center\u003e \u003chr\u003e\u003ccenter\u003eAPISIX\u003c/center\u003e \u003c/html\u003e`     |              | Response body.                                             |\n| error_503.content-type | string  | False    | `text/html`                                                                                                                                                   |              | Response content type.                                     |\n\n\u003e [!IMPORTANT]\n\u003e Plugin metadata set global values, shared accross all plugin instances. For example, if we have 2 different routes with `error-page` plugin enabled, `plugin_metadata` values will be the same for both of them.\n\n### Enable Plugin\n\nThe examples below enable `error-page` plugin globally. With these configurations, APISIX will return a custom error message for status codes `404` and `500`, on every route (even on undefined ones).\n\n#### Traditional\n\nConfigure the plugin metadata:\n\n```bash\ncurl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-page  -H \"X-API-KEY: $admin_key\" -X PUT -d '\n{\n  \"enable\": true,\n  \"error_404\": {\n    \"body\": \"{\\\"status_code\\\":404,\\\"error\\\":\\\"Not Found\\\"}\",\n    \"content-type\": \"application/json\"\n  },\n  \"error_500\": {\n    \"body\": \"{\\\"status_code\\\":500,\\\"error\\\":\\\"API Gateway Error\\\"}\",\n    \"content-type\": \"application/json\"\n  },\n}'\n```\n\nEnable the plugin globally, using global rules:\n\n```bash\ncurl http://127.0.0.1:9180/apisix/admin/global_rules/error-page  -H \"X-API-KEY: $admin_key\" -X PUT -d '\n{\n  \"plugins\": {\n    \"error-page\": {}\n  }\n}'\n```\n\n#### Standalone\n\nConfigure the plugin metadata:\n\n```yaml\nplugin_metadata:\n  - id: error-page\n    enable: true\n    error_404:\n      body: |\n        {\n          \"status_code\": 404,\n          \"error\": \"Not Found\"\n        }\n      content-type: \"application/json\"\n    error_500:\n      body: |\n        {\n          \"status_code\": 500,\n          \"error\": \"API Gateway Error\"\n        }\n      content-type: \"application/json\"\n```\n\nEnable the plugin globally, using global rules:\n\n```yaml\nglobal_rules:\n  - id: generic_error_page\n    plugins:\n      error-page: {}\n```\n\n### Example Usage\n\nSend some request to test error pages:\n\n- Route not defined (overrides default error page for 404):\n\n  ```bash\n  curl -i \"localhost:9080/unknown\"\n  ```\n\n  Response:\n\n  ```bash\n  HTTP/1.1 404 Not Found\n  Content-Type: application/json\n  Connection: keep-alive\n  Server: APISIX/3.12.0\n  Content-Length: 49\n\n  {\n    \"status_code\": 404,\n    \"error\": \"Not Found\"\n  }\n  ```\n\n- Status code 500 returned from APISIX:\n  \n  ```bash\n  curl -i \"localhost:9080/apisix_status/500\"\n  ```\n\n  Response:\n\n  ```bash\n  HTTP/1.1 500 Internal Server Error\n  Content-Type: application/json\n  Connection: close\n  Server: APISIX/3.12.0\n  Content-Length: 57\n\n  {\n    \"status_code\": 500,\n    \"error\": \"API Gateway Error\"\n  }\n  ```\n\n[Back to TOC](#table-of-contents)\n\n## Examples\n\nFolder [`examples/`](examples/) contains a simple example that shows how to setup APISIX locally on Docker, and load `error-page` plugin.\n\nFor more example ideas, have a look at [github.com/mikyll/apisix-examples](https://github.com/mikyll/apisix-examples).\n\n[Back to TOC](#table-of-contents)\n\n### Standalone Example\n\n#### Setup\n\nSee [`apisix.yaml`](examples/apisix-docker-standalone/conf/apisix.yaml).\n\nRun the following command to setup the example:\n\n```bash\ndocker compose -f examples/apisix-docker-standalone/compose.yaml up\n```\n\n#### Test Routes\n\nRun [`test_routes.sh`](examples/utils/test_routes.sh) to send testing requests.\n\n[Back to TOC](#table-of-contents)\n\n## Learn More\n\n- [APISIX Source Code](https://github.com/apache/apisix)\n- [APISIX Deployment Modes](https://apisix.apache.org/docs/apisix/deployment-modes/)\n- [Developing custom APISIX plugins](https://apisix.apache.org/docs/apisix/plugin-develop)\n- [APISIX testing framework](https://apisix.apache.org/docs/apisix/internal/testing-framework)\n- [APISIX debug mode](https://apisix.apache.org/docs/apisix/debug-mode/)\n- [NGiNX variables](https://nginx.org/en/docs/http/ngx_http_core_module.html#variables)\n- [APISIX Examples](https://github.com/mikyll/apisix-examples)\n\n\u003c!-- GitHub Shields --\u003e\n\n[apisix-shield]: https://custom-icon-badges.demolab.com/badge/APISIX-grey.svg?logo=apisix_logo\n[apisix-url]: https://apisix.apache.org/\n[nginx-shield]: https://img.shields.io/badge/Nginx-%23009639.svg?logo=nginx\n[nginx-url]: https://nginx.org/en/\n[lua-shield]: https://img.shields.io/badge/Lua-%232C2D72.svg?logo=lua\u0026logoColor=white\n[lua-url]: https://www.lua.org/\n[perl-shield]: https://img.shields.io/badge/Perl-%2339457E.svg?logo=perl\u0026logoColor=white\n[perl-url]: https://www.perl.org/\n[yaml-shield]: https://img.shields.io/badge/YAML-%23ffffff.svg?logo=yaml\u0026logoColor=151515\n[yaml-url]: https://yaml.org/\n[build-status-shield]: https://github.com/mikyll/apisix-plugin-template/actions/workflows/ci.yml/badge.svg\n[build-status-url]: https://github.com/mikyll/apisix-plugin-template/actions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikyll%2Fapisix-plugin-error-page","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikyll%2Fapisix-plugin-error-page","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikyll%2Fapisix-plugin-error-page/lists"}