# Static IP for Fly.io

Source: https://prontaro.com/docs/integrations/fly-io/

Every Machine in your Fly.io app can reach allowlisted APIs and databases from one stable IPv4, even as workloads scale or migrate.

On Fly.io, Anycast and dedicated IPv4 addresses only handle inbound traffic, while outbound calls leave from the shared worker host. Fly’s native static egress IPs are tied to individual Machines and cannot be shared with CI or external tools. Prontaro attaches one dedicated `/32` to your whole app through an HTTPS proxy, a Relay URL, or a background `prontaro forward` process.

## Which method to choose

| Fly.io workload | Prontaro method | Best for |
| --- | --- | --- |
| **Partner HTTPS APIs and payment gateways** | `PRONTARO_PROXY_URL` (HTTPS proxy `:443`) | End-to-end TLS and mTLS; no CLI needed in the image |
| **Single REST API without proxy libraries** | [Relay URL](https://prontaro.com/docs/outbound/relay.md) (`PRONTARO_RELAY_URL`) | Swap only the base URL in built-in `fetch` |
| **External databases and TCP without SOCKS5** | Background process `prontaro forward` + `PRONTARO_KEY` | Local `127.0.0.1:<port>` listener inside the same Machine |

## Prerequisites

- A Prontaro account on Dedicated (from $12/mo, 100 GB traffic) or Pro ([plans](https://prontaro.com/docs/billing/plans.md)).
- A dedicated IPv4 in the Prontaro location closest to your Fly.io region (available locations are shown in the dashboard).
- A Fly.io app and `flyctl` (`fly`) installed locally.

## Step 1. Create proxy credentials and allowlist your IP

Add your dedicated Prontaro IPv4 (`/32`) to the partner API or database allowlist, then create proxy credentials for Fly.io in the dashboard. Leave the **To** destination list open until you verify the outbound IP.

1. Open **IP addresses** in [my.prontaro.com](https://my.prontaro.com/ips) and click **Create proxy credentials**.
2. Name them `fly-prod` and copy the `HTTPS` URL on port `:443`.

IP addresses Proxy credentials [Open in dashboard](https://my.prontaro.com/ips)

## Step 2. Store the secret with `fly secrets set`

Save the proxy URL in Fly.io encrypted secrets:

```bash
fly secrets set PRONTARO_PROXY_URL="https://u_fly:s3cr3t@<entry>.prontaro.io:443"
```

`fly secrets set` automatically triggers a rolling Machine restart. When setting multiple secrets at once (for example, alongside `PARTNER_API_TOKEN`), pass `--stage` and roll them out together on your next `fly deploy`.

> **Keep Fly 6PN private networking out of the proxy**
>
> Do not set a process-wide `HTTPS_PROXY` without exclusions: Fly services talk over the 6PN private network (`.internal`, `.flycast`, `fdaa::/16`).
>
> Pass `PRONTARO_PROXY_URL` only to external API clients, or set `NO_PROXY=localhost,127.0.0.1,.internal,.flycast` if you must use a global proxy variable.

## Step 3. Send traffic through your static IP

### Option A. HTTPS APIs with `PRONTARO_PROXY_URL`

Node.js 20+ example using `undici` (create `ProxyAgent` once at startup):

```js
// src/partner.mjs
import { fetch, ProxyAgent } from 'undici';

const agent = new ProxyAgent({
  uri: process.env.PRONTARO_PROXY_URL,
  connections: 20,
});

export async function fetchPartnerStatus() {
  const res = await fetch('https://api.example.com/v1/status', {
    dispatcher: agent,
    headers: { Authorization: `Bearer ${process.env.PARTNER_API_TOKEN}` },
    signal: AbortSignal.timeout(15_000),
  });
  if (!res.ok) throw new Error(`Partner API error: ${res.status}`);
  return res.json();
}
```

See [HTTP client examples](https://prontaro.com/docs/languages/) for Python, Go, PHP, and Java snippets.

### Option B. Background process `prontaro forward` with `PRONTARO_KEY`

Each Fly Machine runs a single container inside a lightweight VM. To reach an external database (PostgreSQL, MySQL, SFTP) with a driver lacking SOCKS5 support, bundle the static `prontaro` binary and run `prontaro forward` alongside your app.

1. Open the **CLI** tab in [my.prontaro.com](https://my.prontaro.com/), issue a token named `fly-prod`, and save it as `PRONTARO_KEY` in Fly.io (`prontaro CLI` reads `PRONTARO_KEY` directly — no `prontaro login` step is required inside the container):
  CLI [Open in dashboard](https://my.prontaro.com/cli)
  ```bash
  fly secrets set PRONTARO_KEY="<token>"
  ```
2. Install `prontaro` (as `root`, `install.sh` places the binary directly in `/usr/local/bin/prontaro`) and add an entrypoint script in your `Dockerfile`:

```dockerfile
FROM node:22-alpine

RUN apk add --no-cache ca-certificates curl netcat-openbsd \
 && curl -fsSL https://prontaro.com/install.sh | sh

WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node", "server.mjs"]
```

1. Start `prontaro forward` in `docker-entrypoint.sh` (with `--no-input` to disable interactive prompts) and wait for `127.0.0.1:15432` before starting your app. On startup refusals (such as an unpaid or blocked account), `prontaro` exits immediately with a non-zero code instead of waiting, so the entrypoint exits `1` and Fly.io restarts the Machine according to its `[[restart]]` policy in `fly.toml` (default `policy = "on-failure"` with `retries = 10`, or `policy = "always"` to keep retrying until the issue is resolved):

```sh
#!/bin/sh
set -eu

prontaro forward 15432 db.example.com:5432 --ip 203.0.113.10 --no-input --json &
FWD_PID=$!
trap 'kill "$FWD_PID" 2>/dev/null || true' INT TERM EXIT

for _ in $(seq 1 30); do
  if nc -z 127.0.0.1 15432; then
    break
  fi
  kill -0 "$FWD_PID" 2>/dev/null || break
  sleep 0.5
done

if ! nc -z 127.0.0.1 15432; then
  echo "prontaro forward did not become ready on 127.0.0.1:15432" >&2
  exit 1
fi

exec "$@"
```

Your app inside the Fly Machine connects to `127.0.0.1:15432`, and the remote database sees your dedicated static IPv4.

## Step 4. Verify the outbound IP

Run a check inside a running Fly Machine against `api.ipify.org` before tightening allowed destinations:

```
 fly ssh console -C 'sh -c "curl -fsS --proxy \"$PRONTARO_PROXY_URL\" https://api.ipify.org"'
203.0.113.10
```

Confirm the printed IP matches your dedicated IPv4 in [my.prontaro.com](https://my.prontaro.com/).

## Step 5. Lock down allowed destinations

After verifying the IP, restrict `fly-prod` to the exact partner hosts and ports:

1. Open **IP addresses → Proxy credentials** in [my.prontaro.com](https://my.prontaro.com/ips), select `fly-prod`, switch to **Access**, and add `api.example.com:443` under **To**.
2. Save.

IP addresses Proxy credentials Access [Open in dashboard](https://my.prontaro.com/ips)

## Fly.io notes and limits

- **Match regions:** pick the Prontaro location in the dashboard closest to your Fly.io `primary_region` to minimize latency.
- **Horizontal scaling:** all Machines share your IP’s concurrent connection limit ([limits](https://prontaro.com/docs/billing/limits.md)). Cap HTTP `connections` and DB pool size per Machine so scale-outs stay within quota.
- **Explicit `--ip` on Pro:** with multiple dedicated IPs, always pass `--ip <your-IP>` to `prontaro forward` because non-interactive Machines cannot answer an IP prompt.
- **[BGP failover](https://prontaro.com/docs/outbound/failover.md):** on a server outage, your `/32` moves to a standby Prontaro server without allowlist edits. Active TCP sessions close, `prontaro forward` reconnects automatically, and new HTTP requests use the standby.

## Common errors

| Symptom | Cause | Fix |
| --- | --- | --- |
| `407 Proxy Authentication Required` | Typo in the secret, or new credentials are still propagating (a few seconds). | Copy the exact URL under [IP addresses](https://my.prontaro.com/ips), run `fly secrets set`, and retest. |
| `403 Forbidden` from proxy | Target host or port is missing from the **To** list. | Add `<host>:443` to `fly-prod` destination rules in the dashboard. |
| `.internal` or `.flycast` calls broke | Global `HTTPS_PROXY` hijacked Fly 6PN traffic. | Remove the global proxy or add `.internal,.flycast` to `NO_PROXY`. |
| `You have 2 addresses — choose which one` | Account has multiple IPs and `prontaro forward` has no `--ip` flag. | Add `--ip <your-IP>` to `docker-entrypoint.sh`. |

## Next steps

- [Static IP and tunnels in Docker](https://prontaro.com/docs/integrations/docker.md) — container and Docker Compose patterns.
- [PostgreSQL and AWS RDS with a static IP](https://prontaro.com/docs/integrations/postgres.md) — TLS and driver setup for allowlisted databases.
- [Local port forwarding (`prontaro forward`)](https://prontaro.com/docs/outbound/forward.md) — background TCP forwarding options and flags.
- [HTTP & SOCKS5 proxy](https://prontaro.com/docs/outbound/proxy.md) — proxy credentials, protocols, and allowed destination rules.
