# Configure HTTP and HTTPS Ports

import Tabs from '~/components/tabs/Tabs'

import Apiv4Rollout from '~/includes/snippets/apiv4Rollout/en/snippet.mdx'

<Apiv4Rollout />

With Azion, you can customize your application's delivery address port as well as from which ports of your origin address your content is retrieved. This dual customization provides complete control over how your content is fetched from the origin and delivered to your users for both HTTP and HTTPS protocols.

The choice of delivery ports are limited to those supported by Azion. However, for retrieving the content from your origins, you can fetch your content from the appropriate origin port, as long as the port exists.

There are separate instructions for API v3 using [legacy Origins](/en/documentation/products/build/applications/origins/) settings and API v4 using the new [Connectors](/en/documentation/products/secure/connectors/) product.

:::tip
If you're not sure which steps apply to your account, see [the Verify Your Account Migration guide](/en/documentation/products/guides/verify-account-migration/) to determine if your account has already been migrated.
:::


---

## Available port combinations

There are several port combinations you can configure for your application.

| Use case | Example origin URL | Example delivery URL |
| --- | --- | --- |
| Application served from default origin ports to default delivery ports | `https://origin.com:443` | `https://delivery.com:443` |
| Application served from a default origin port to a different protocol of a default delivery port | `http://origin.com:80` | `https://delivery.com:443` |
| Application served from a default origin port to a custom delivery port | `http://origin.com:80` | `http://delivery.com:8080` | 
| Application served from a custom origin port to a default delivery port | `https://origin.com:9443` | `https://delivery.com:443` |
| Application served from a custom origin port to a custom delivery port | `https://origin.com:8443` | `https://delivery.com:9443` |

---

## Configuring ports

<Tabs client:visible>
    <Fragment slot="tab.consoleedgeconnector">Console - Connectors</Fragment>
    <Fragment slot="tab.consoleorigins">Console - Origins</Fragment>

<Fragment slot="panel.consoleedgeconnector">

To configure your application's origin and delivery ports, follow these steps:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/).
2. Check the solutions for each use case below.

### Default origin port to default application port

If you want your content to be drawn from a default port and served in a default application port, configure your application as follows:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Connectors**.
2. Select the edge connector you want to configure.
3. Fill in the required fields.
4. In **Transport Protocol Policy** select **Preserve**. 
5. In **Address**, type the hostname of your origin. Example: `yourorigin.com`.
6. Click the **Save** button.

Now to configure your delivery settings, follow these steps:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Workloads**.
2. Select the desired Workload.
3. In the **Protocol Settings** section, select one of the default HTTP or HTTPS ports. Example: `80`.
- If you determine your application is delivered via HTTP only, you'll only be able to select port `80`. Enabling both HTTP and HTTPS will enable the HTTPS port `443`.
4. Click the **Save** button. 

With this option enabled, access to your application through default ports will be through the default ports of your origin.

### Modified default origin port to default application port

You can modify the default port your application's origin by enforcing protocols. For example, you can determine that your application will be delivered in HTTPS but the communication with origin servers should be made exclusively in HTTP. To do so, configure your application as follows:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Connectors**.
2. In **Connectors**, select an existing Connector or add a new one.
3. Fill in the required fields.
4. In **Transport Protocol Policy** select **Force HTTP** if you want the edge to access your content explicitly through HTTP.
5. Click the **Save** button.
6. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Workloads**.
7. Select the desired Workload.
8. In the **Protocol Settings** section, select one of the default HTTP and HTTPS ports. Example: `80` and `443`.
9. Click the **Save** button.

:::tip
You can also use **Rules Engine** and [create a rule](/en/documentation/products/guides/build/work-with-rules-engine/) using the behavior **Redirect HTTP to HTTPS** to prevent your users from accessing application through the HTTP protocol given a specific scenario.
:::

### Custom origin port to default application port

You can use the `host:port` notation to specify the port from which your content will be retrieved and deliver it through a default application port. In this case, your content will be retrieved from a custom port of your origin and delivered through the default port you selected. To do so:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Connectors**.
2. In **Connectors**, select an existing Connector or add a new one.
3. Fill in the required fields.
4. In **Transport Protocol Policy** select **Preserve**.
5. In **Address**, type the hostname of your origin and in **HTTP/HTTPS PORT**, add the custom port.
6. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Workloads**.
7. Select the desired Workload.
8. In the **Protocol Settings** section, select one of the default HTTP or HTTPS ports. Example: `443`.
9. Click the **Save** button.

### Default origin port to custom application port

To deliver your content from a default origin port to a custom application port:
To deliver your content from a default origin port to a custom application port, follow these steps:
1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Connectors**.
2. In **Connectors**, select an existing Connector or add a new one.
3. Fill in the required fields.
4. In **Transport Protocol Policy** select **Preserve**.
5. In **Address**, type the hostname of your origin. Example: `yourorigin.com`.
6. Click the **Save** button.
7. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Workloads**.
8. Select the desired Workload.
9. In the **Protocol Settings** section, select one of the custom HTTP or HTTPS ports. Example: `9443`.
10. Click the **Save** button.

### Custom origin port to custom application port

If you want requests to be directed to an origin only using custom ports, you must specify that requests to your application made from the custom port are directed to the correct port. To do so:

1. On **Workloads**, under **HTTP Ports**, check which custom ports have been selected.
2. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Connectors**.
3. Click the **+ Connectors** button.
4. Give your Connector an easy-to-remember name. Example: `myconnetor:8080`.
5. Fill in the required fields.
6. In **Transport Protocol Policy** select **Preserve**.
7. In **Address**, type the hostname of your origin and in **HTTP/HTTPS PORT**, add the custom port.
8. Fill in the remaining fields with the desired values.
9. Click the **Save** button.

Now you need to configure your application so that when requests are received in custom ports, they're redirected to the correct origin port:

1. Go to the **Rules Engine** tab of the application.
2. Click the **+ Rule** button.
3. Give your rule an easy-to-remember name. Example: `Set Origin :8080`.
4. Select **Request Phase**.
5. Under the section **Criteria**, select the variable `${server_port}`.
6. For a comparison operator, select **is equal to**.
7. As an argument, add the desired port. Example: `8080`.
8. In the **Behaviors** section, select the behavior **Set Connector**.
9. Select the Connector created in the previous instructions.
10. Click the **Save** button.

</Fragment>

<Fragment slot="panel.consoleorigins">

To configure your application's origin and delivery ports:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Applications**.
2. Select the application you want to configure.
3. Check the solutions for each use case below.


### Default origin port to default application port

If you want your content to be drawn from a default port and served in a default application port, configure your application as follows:

1. In the **Origins** tab, select the default origin or add a new origin.
2. Fill in the required fields.
3. Keep the option **Preserve HTTP/HTTPS protocol** selected. 
4. In **Address**, type the hostname of your origin. Example: `yourorigin.com`.
5. Click the **Save** button.
6. In the **Main Settings** tab of your application, select one of the default HTTP or HTTPS ports. Example: `80`.
- If you determine your application is delivered via HTTP only, you'll only be able to select port `80`. Enabling both HTTP and HTTPS will enable the HTTPS port `443`.
7. Click the **Save** button. 

With this option enabled, access to your application through default ports will be through the default ports of your origin.

### Modified default origin port to default application port

You can modify the default port your application's origin by enforcing protocols. For example, you can determine that your application will be delivered in HTTPS but the communication with origin servers should be made exclusively in HTTP. To do so, configure your application as follows:


1. In the **Origins** tab, select the default origin or add a new origin.
2. Fill in the required fields.
3. In the section **Protocol Policy**, select **Enforce HTTP** if you want the edge to access your content explicitly through HTTP.
4. Click the **Save** button.
5. In the **Main Settings** tab of your application, select one of the default HTTP and HTTPS ports. Example: `80` and `443`.
6. Click the **Save** button.

:::tip
You can also use **Rules Engine** and [create a rule](/en/documentation/products/guides/build/work-with-rules-engine/) using the behavior **Redirect HTTP to HTTPS** to prevent your users from accessing application through the HTTP protocol given a specific scenario.
:::

### Custom origin port to default application port

You can use the `host:port` notation to specify the port from which your content will be retrieved and deliver it through a default application port. In this case, your content will be retrieved from a custom port of your origin and delivered through the default port you selected. To do so:

1. In the **Origins** tab, select the default origin or add a new origin.
2. Fill in the required fields.
3. Keep the option **Preserve HTTP/HTTPS protocol** enabled.
4. In **Address**, type the hostname of your origin and add the port notation with the custom port. Example: `yourorigin.com:8080`.
5. Click the **Save** button.
6. In the **Main Settings** tab of your application, select one of the default HTTP or HTTPS ports. Example: `443`.
7. Click the **Save** button.

### Default origin port to custom application port

To deliver your content from a default origin port to a custom application port:

1. In the **Origins** tab, select the default origin or add a new origin.
2. Fill in the required fields.
3. Keep the option **Preserve HTTP/HTTPS protocol** enabled.
4. In **Address**, type the hostname of your origin. Example: `yourorigin.com`.
5. Click the **Save** button.
6. In the **Main Settings** tab of your application, select one of the custom HTTP or HTTPS ports. Example: `9443`.
7. Click the **Save** button.

### Custom origin port to custom application port

If you want requests to be directed to an origin only using custom ports, you must specify that requests to your application made from the custom port are directed to the correct port. To do so:

1. On the **Main Settings** tab, under **HTTP Ports**, check which custom ports have been selected.
2. Go to the **Origins** tab.
3. Click the **+ Origin** button.
4. Give your origin an easy-to-remember name. Example: `Origin:8080`.
5. Fill in the required fields.
6. Keep the option **Preserve HTTP/HTTPS protocol** enabled. 
7. In **Address**, use the `host:port` notation. Example: `yourorigin.com:8080`.
8. Fill in the remaining fields with the desired values.
9. Click the **Save** button.

Now you need to configure your application so that when requests are received in custom ports, they're redirected to the correct origin port:

1. Go to the **Rules Engine** tab of the application.
2. Click the **+ Rule** button.
3. Give your rule an easy-to-remember name. Example: `Set Origin :8080`.
4. Select **Request Phase**.
5. Under the section **Criteria**, select the variable `${server_port}`.
6. For a comparison operator, select **is equal to**.
7. As an argument, add the desired port. Example: `8080`.
8. In the **Behaviors** section, select the behavior **Set Origin**.
9. Select the origin created in the previous instructions.
10. Click the **Save** button.

</Fragment>
</Tabs>

If more than one custom port was selected for the application, you may create additional rules, repeating the previous steps for each custom port selected.

From this moment on, when a request is made to the application using a custom port, the edge points the request to the assigned port when accessing the origin.