Set the Host header and path prefix for an origin
Choose the Host header a connector sends and the path it prepends, so the origin serves the right site and directory.
You can set the Host header a connector sends to its origin, and a path it prepends to every request, from Azion Console, the Azion CLI, or the API. Both settings apply to a connector of type http. The examples use httpbin.org as the origin, because it answers with the request it received, so each setting shows in its response. Replace it with the host name of your origin.
Select the interface you use. The prerequisites and every task on this page follow that choice.
Prerequisites
- A connector of type
http, and a workload whose application points a rule at the connector with theSet Connectorbehavior. To create both, refer to Connectors quickstart. - The workload domain, or a domain of your own, that the workload answers on.
- Access to Azion Console.
Send the origin’s own host name
By default, host is ${host}, which sends the host the client requested. Keep the default for an origin that serves several virtual hosts and reads each request under its public name. Set a literal value when the origin answers only under its own name. The connector then sends that name for every request.
The CLI updates a connector from a file that carries the whole connector: its name, type, attributes.addresses, and the connection options you set. A file with connection_options alone fails with Failed to decode the given 'json' file. Copy your connector’s current values into the file, then change host.
To set the host name with the Azion CLI, save the connector as connector.json:
Then update the connector from the file. Replace <connector-id> with the ID of your connector:
The connector now sends Host: httpbin.org to the origin.
To send the client’s host again, set the value back to ${host}.
Prepend a path
The path goes in front of the path the client requested, so the origin serves content from one of its directories. With /anything, a request for /get reaches the origin as /anything/get. With /secure, a request for https://<your-domain>/index.html reaches the origin as /secure/index.html. The prefix never appears in the client’s URL. The value starts with /, and the default is no prefix.
For a bucket of Object Storage, a connector of type storage carries its own prefix instead. For more information, refer to Connector settings.
To set the path with the Azion CLI, add path_prefix to the whole connector in connector.json:
Then update the connector from the file:
To read the connection options back:
The output carries the new path and the host name from the file:
path_prefix carries /anything, and host carries the name from the file.
Verify what the origin receives
A connector change needs no new deployment. It reaches traffic over several minutes, and each data center applies it at its own moment. For more information, refer to How Connectors works.
To see the request the origin received, send a request through your workload. Replace <workload-domain> with the workload domain or your own domain:
httpbin.org answers with the request it received, as JSON. Two fields show the connector’s settings: headers.Host is the Host header, and url carries the path the origin received. With host at ${host} and the path prefix /anything, the response reads:
url carries /anything/get, so the connector prepends the path prefix. headers.Host carries the workload domain, the host the client requested. With host at httpbin.org, headers.Host reads httpbin.org instead. Send the request several times: an answer with the previous values comes from a data center that has not applied the change yet.