# Configure Proxy Mirror

The [`proxy-mirror`](https://docs.api7.ai/hub/proxy-mirror.md) plugin allows you to mirror real requests from your production environment to a separate service for testing or analysis. The response from the mirrored service is ignored, ensuring no impact on the original request's performance or outcome.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

* An API7 Enterprise instance is running.
* A Gateway Group is created and a Gateway instance is running.
* A [token from the Dashboard](https://docs.api7.ai/api7-gateway/reference/obtain-dashboard-token.md).

## Configure Traffic Mirroring[​](#configure-traffic-mirroring "Direct link to Configure Traffic Mirroring")

The following configuration mirrors all incoming requests to a secondary service running at `http://test-server:8080`.

* Admin API
* ADC

```
curl -k "https://localhost:7443/apisix/admin/services/proxy-mirror-service?gateway_group_id={gateway_group_id}" -X PUT \

  -H "X-API-KEY: ${API_KEY}" \

  -H "Content-Type: application/json" \

  -d '{

    "name": "proxy-mirror-service",

    "upstream": {

      "type": "roundrobin",

      "scheme": "http",

      "nodes": [

        {

          "host": "httpbin.org",

          "port": 80,

          "weight": 100

        }

      ]

    }

  }'



curl -k "https://localhost:7443/apisix/admin/routes/proxy-mirror-route?gateway_group_id={gateway_group_id}" -X PUT \

  -H "X-API-KEY: ${API_KEY}" \

  -H "Content-Type: application/json" \

  -d '{

    "name": "proxy-mirror-route",

    "methods": ["GET"],

    "paths": ["/anything/mirror"],

    "service_id": "proxy-mirror-service",

    "plugins": {

      "proxy-mirror": {

        "host": "http://test-server:8080",

        "path": "/mirror-receiver",

        "sample_ratio": 1

      }

    }

  }'
```

adc.yaml

```
services:

  - name: proxy-mirror-service

    upstream:

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1

    routes:

      - name: proxy-mirror-route

        uris:

          - /anything/mirror

        methods:

          - GET

        plugins:

          proxy-mirror:

            host: "http://test-server:8080"

            path: "/mirror-receiver"

            sample_ratio: 1

    labels:

      docs-example: proxy-mirror-service
```

Preview the changes owned by this example and confirm that the diff contains no unintended updates or deletions:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=proxy-mirror-service
```

Synchronize the reviewed configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=proxy-mirror-service
```

## Configure Sampled Traffic Mirroring[​](#configure-sampled-traffic-mirroring "Direct link to Configure Sampled Traffic Mirroring")

To mirror only a small percentage of your traffic, you can adjust the `sample_ratio` field.

* Admin API
* ADC

```
curl -k "https://localhost:7443/apisix/admin/services/sampled-proxy-mirror-service?gateway_group_id={gateway_group_id}" -X PUT \

  -H "X-API-KEY: ${API_KEY}" \

  -H "Content-Type: application/json" \

  -d '{

    "name": "sampled-proxy-mirror-service",

    "upstream": {

      "type": "roundrobin",

      "scheme": "http",

      "nodes": [

        {

          "host": "httpbin.org",

          "port": 80,

          "weight": 100

        }

      ]

    }

  }'



curl -k "https://localhost:7443/apisix/admin/routes/sampled-proxy-mirror-route?gateway_group_id={gateway_group_id}" -X PUT \

  -H "X-API-KEY: ${API_KEY}" \

  -H "Content-Type: application/json" \

  -d '{

    "name": "sampled-proxy-mirror-route",

    "methods": ["GET"],

    "paths": ["/anything/mirror-sampled"],

    "service_id": "sampled-proxy-mirror-service",

    "plugins": {

      "proxy-mirror": {

        "host": "http://test-server:8080",

        "sample_ratio": 0.1

      }

    }

  }'
```

adc.yaml

```
services:

  - name: sampled-proxy-mirror-service

    upstream:

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1

    routes:

      - name: sampled-proxy-mirror-route

        uris:

          - /anything/mirror-sampled

        methods:

          - GET

        plugins:

          proxy-mirror:

            host: "http://test-server:8080"

            sample_ratio: 0.1

    labels:

      docs-example: sampled-proxy-mirror-service
```

Preview the changes owned by this example and confirm that the diff contains no unintended updates or deletions:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=sampled-proxy-mirror-service
```

Synchronize the reviewed configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=sampled-proxy-mirror-service
```

## Validate the Configuration[​](#validate-the-configuration "Direct link to Validate the Configuration")

Send a request to the main service:

```
curl "http://127.0.0.1:9080/anything/mirror"
```

Check the logs of your mirrored service (`http://test-server:8080`) to verify that it received the mirrored request. Since mirroring happens asynchronously, the original client will not experience any delay.

The mirrored target must be reachable from the gateway instances themselves, not just from your local shell or the control plane. In a local Docker setup, exposing the mirror receiver on a host port is often the simplest way to make it reachable.

## Next Steps[​](#next-steps "Direct link to Next Steps")

* [Configure Proxy Cache](https://docs.api7.ai/api7-gateway/how-to-guides/traffic-management/proxy-cache.md) — improve performance by caching responses.
* [Configure Fault Injection](https://docs.api7.ai/api7-gateway/how-to-guides/traffic-management/fault-injection.md) — test your application resilience.
* [Configure Response Rewrite](https://docs.api7.ai/api7-gateway/how-to-guides/traffic-management/response-rewrite.md) — modify response data before returning to the client.
