Custom Pages quickstart
Create a custom page set that replaces your origin's 404 with a page of your own, assign it in the workload's deployment, and see it served.
This guide instructs you through replacing the 404 your origin returns with your first page from Custom Pages.
- Create a custom page set with one page for status code
404. - Assign the set in the deployment of your workload.
- Request a path your origin does not have and get your own page in its place.
Four objects take part, and each one links to the next:
- The connector holds your error page at a path. It already exists. For more information, refer to Connectors.
- The custom page set binds status code
404to that path on the connector. - The deployment of the workload names the set, next to the application it already names.
- The request reaches a path that the application’s connector answers with
404, and the set replaces that answer.
A set changes nothing until a deployment names it. When the application’s connector answers 404, the visitor receives the content of your page in place, with no redirect, and with the status code the page sets. This guide covers Azion Console and the API. The Azion CLI cannot change a deployment that already exists, so it cannot assign a set to your workload.
Select the interface you use. The prerequisites and every stage on this page follow that choice.
Prerequisites
- A workload whose deployment names an application. To create one, refer to Workloads quickstart.
- A path that your application’s connector answers with
404, such as a page that does not exist. - A connector that serves your error page at a path. To create one, refer to Connectors.
- Access to Azion Console. To sign in, refer to How to access Azion Console.
Create the custom page set
A custom page set is a named list of pages, and it needs at least one. Each page binds one status code to a path on a connector, and it can answer with a status code of its own. The set in this stage keeps the page in cache for 0 seconds and answers with 404.
To create the set with the API, send a POST request to the custom pages endpoint. Replace [TOKEN VALUE] with your personal token and <connector-id> with the ID of your connector. Replace /html with the path at which the connector serves your page:
The API answers with 201 and the new set, its id included. A request with an empty pages list is refused with Ensure this field has at least 1 elements. Record the id of the new set to assign it to your workload. The set exists with one page for code 404, and it serves nothing until you assign it.
Assign the set to your workload
The deployment of a workload names the application, the firewall, and the custom page set that serve its traffic. A workload holds one deployment, so you assign the set by editing that deployment. The application it already names stays in place.
To assign the set with the API, send a PATCH request to the deployment of your workload. strategy.attributes holds the application, the firewall, and the custom page set of the deployment. Send the application the deployment names today, and its firewall if it has one, with the ID of your set in custom_page. Replace <workload-id>, <deployment-id>, <application-id>, and <custom-page-id>:
The API answers with 202. The deployment of the workload names your set in strategy.attributes.custom_page.
Request a page your origin answers with 404
The check is the same whichever interface assigned the set. In the command, replace <your-workload-domain> with the workload domain of your workload, of the form <id>.map.azionedge.net. Replace <missing-path> with the path your application’s connector answers with 404.
An assigned set does not serve at once. The change to the deployment spreads across Azion’s distributed infrastructure, and that takes several minutes, with no guaranteed duration. While it spreads, a request can receive either your origin’s 404 or your page. Repeat the request until your page answers. For more information, refer to Propagation.
Send a request to the missing path and print the response headers with the body:
The response keeps status 404, from the page’s custom_status_code. Its body is the document your connector serves at the page’s path. When that document is an HTML page, the response reads:
The response carries no Location header, so the client is not redirected. Your workload answers a missing path with your own page.