# Ibexa DXP with Fastly


Ibexa DXP is a “commercial extended” version of Ibexa OSS that includes, among other things, support for push-based purging on the Fastly CDN.

## Remove Varnish configuration

In Ibexa DXP, Varnish is enabled by default when deploying on Upsun Fixed.  
To use Fastly, Varnish must be disabled:

- Remove environment variable `TRUSTED_PROXIES: "REMOTE_ADDR"` in [`.platform.app.yaml`](https://github.com/ibexa/post-install/blob/4.6/resources/platformsh/ibexa-commerce/4.6/.platform.app.yaml#L66)
- Remove the Varnish service in [`.platform/services.yaml`](https://github.com/ibexa/post-install/blob/4.6/resources/platformsh/common/4.6/.platform/services.yaml#L80-L87)
- In [`.platform/routes.yaml`](https://github.com/ibexa/post-install/blob/4.6/resources/platformsh/common/4.6/.platform/routes.yaml#L3),
   change routes to use `myapp` instead of the `varnish` service you removed in previous step:

```diff {no-copy="true"}
 "https://{default}/":
     type: upstream
-     upstream: "varnish:http"
+     upstream: "app:http"
```

## Setting up Ibexa DXP to use Fastly

Ibexa DXP's documentation includes instructions on how to [configure Ibexa DXP for Fastly](https://doc.ibexa.co/en/latest/infrastructure_and_maintenance/cache/http_cache/reverse_proxy/#using-varnish-or-fastly).
Follow the steps there to prepare Ibexa DXP for Fastly.

## Set credentials

The best way to provide the Fastly credentials and configuration to Ibexa DXP on Upsun Fixed is via environment variables.
That way private credentials are never stored in Git.

Using the CLI, run the following commands to set the configuration on your production environment
(assumed to be `main` below, but change it to fit your setup).
(Note that they inherit to all other environments by default unless overridden.)

```bash
ibexa_cloud variable:create -e main --level environment env:HTTPCACHE_PURGE_TYPE --value 'fastly'
ibexa_cloud variable:create -e main --level environment env:FASTLY_SERVICE_ID --value 'YOUR_ID_HERE'
ibexa_cloud variable:create -e main --level environment env:FASTLY_KEY --value 'YOUR_TOKEN_HERE'
```

Replacing `YOUR_ID_HERE` with the Fastly Service ID and Key obtained from Fastly.

Note: On a Dedicated Gen 2 cluster, set those values on the `production` branch:

```bash
ibexa_cloud variable:set -e production env:HTTPCACHE_PURGE_TYPE fastly
ibexa_cloud variable:set -e production env:FASTLY_SERVICE_ID YOUR_ID_HERE
ibexa_cloud variable:set -e production env:FASTLY_KEY YOUR_TOKEN_HERE
```

## Setup the correct VCL files

There are two VCL files provided as starting points for using Fastly with Ibexa DXP;
you can find them in `vendor/ibexa/fastly/fastly/ez_*.vcl`.
A VCL snippet can be found in `vendor/ibexa/fastly/fastly/snippet_re_enable_shielding.vcl`.
They handle varying cache by user context hash _(permissions)_
as well as several other needs by Ibexa DXP and it's underlying HttpCache system.

## Configure Fastly

See the alternate [Go-live process for Fastly](https://fixed.docs.upsun.com/domains/cdn.md#enable-mtls) on Upsun Fixed.
This process is the same for any application.

