๐Ÿ‡ช๐Ÿ‡บ Static IP for Next.js

๐Ÿ‡ช๐Ÿ‡บ Static IP for Next.js

Next.js fetch ignores HTTPS_PROXY by default. Wire undici's ProxyAgent once and every server-side call, Server Action, and route handler egresses through two fixed static EU IPs.

Works with App Router, Server Actions, route handlers, and self-hosted Node

app/proxy.ts ยท Next.js

import { ProxyAgent, setGlobalDispatcher }

  from "undici";

// Next.js fetch needs this explicitly

setGlobalDispatcher(

  new ProxyAgent(process.env.HTTPS_PROXY)

);

// now fetch() uses one of your two EU IPs

Why Next.js Apps Get Blocked

Server-side Next.js code calls partner APIs, but the platform it runs on gives it no stable egress.

fetch silently ignores HTTPS_PROXY

Next.js uses Node's native fetch, powered by undici, which does not read HTTPS_PROXY from the environment. Setting the env var alone changes nothing, so developers think the proxy is on while calls still leave from the host IP.

Serverless instances fan out

On Vercel and other serverless platforms, route handlers and Server Actions run across many function instances, each with its own egress IP. A single allowlisted address can never cover them all.

Build-time env inlining pitfalls

Next.js inlines NEXT_PUBLIC_ values at build time. Proxy URLs set that way get baked into the bundle or vanish at runtime, so the egress you configured in dev is missing in production.

Edge runtime can't use undici

Route handlers set to the Edge runtime can't import undici's ProxyAgent. A proxy that works in local dev on the Node runtime then breaks the moment the route runs on the Edge.

When a partner asks for your IP

"Send us the IP that will call our API."

You need an answer that is still true after the next deploy.

Route Next.js Through a Static IP Proxy

Next.js app

OutboundGateway

Two fixed EU IPs

Partner API

The partner API sees one of your two fixed EU IPs, from every route handler and Server Action.

  • Wire undici once with setGlobalDispatcher, and every fetch inherits it.
  • No changes to your components or route signatures.
  • Two IPs with automatic failover, so a hiccup on one never drops a request.

Why Next.js Teams Choose This

  • Two fixed EU IPs your partners can allowlist once and forget about.
  • One undici dispatcher covers App Router fetch, Server Actions, and route handlers.
  • Identical egress on local dev, CI, Docker, and your production Node server.
  • EU-hosted egress, GDPR-aligned, with traffic kept inside EU jurisdiction.

Designed For

App Router backends

Route handlers and Server Actions that call IP-whitelisted partner APIs.

B2B SaaS on Next.js

Full-stack apps integrating with enterprise APIs behind firewalls.

Self-hosted Next.js

Docker or Node deployments that need a predictable egress identity.

EU-regulated teams

Apps that must keep outbound traffic inside the EU.

How It Works

Next.js fetch needs undici wired explicitly. Set it once and every server-side call is proxied.

Option 1: undici ProxyAgent (App Router, recommended)

Set HTTPS_PROXY as a runtime env var, then register a global undici dispatcher once. Every fetch in your App Router then routes through the proxy.

# .env  (runtime only, never NEXT_PUBLIC_)
HTTPS_PROXY=https://USER:PASS@eu-01.outboundgateway.com:8443
// app/proxy.ts
import { ProxyAgent, setGlobalDispatcher } from "undici";

if (process.env.HTTPS_PROXY) {
  setGlobalDispatcher(new ProxyAgent(process.env.HTTPS_PROXY));
}

// app/ip/route.ts
export async function GET() {
  const res = await fetch("https://outboundgateway.com/ip/");
  return Response.json(await res.json()); // one of your two EU IPs
}

๐Ÿ“– Full guide: for per-request agents, retries, and timeout handling, see the Node.js SSL proxy guide.

Option 2: axios with https-proxy-agent

If your Next.js app uses axios instead of fetch, attach an https-proxy-agent to the instance. Remember to URL-encode credentials if the password has special characters.

import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";

const api = axios.create({
  httpsAgent: new HttpsProxyAgent(process.env.HTTPS_PROXY),
});

const { data } = await api.get("https://api.partner.example.com/data", {
  headers: { Authorization: `Bearer ${process.env.PARTNER_TOKEN}` },
});

Option 3: Docker / self-hosted Node

Pass the proxy URL at runtime so credentials never end up in the image.

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
CMD ["npm", "start"]
docker run --rm -p 3000:3000 \
  -e HTTPS_PROXY=https://USER:PASS@eu-01.outboundgateway.com:8443 \
  my-nextjs-app

Built for European Next.js Teams

When a partner cares where your traffic originates, the location of the egress matters.

EU-hosted egress

Your proxy runs on infrastructure inside the European Union, so outbound traffic stays within EU jurisdiction.

GDPR-aligned

Data handling that aligns with European privacy expectations, for teams that keep processing inside the EU.

No US routing

Traffic is not detoured through US-based servers, which keeps your compliance story simple.

Clear outbound identity

Two fixed IPs give auditors and partners a stable, predictable answer about where requests come from.

Why Developers Choose OutboundGateway

Two fixed EU IPs

A pair of static IPs with automatic failover. Allowlist once, keep working.

Built for Node fetch

Works with undici ProxyAgent and https-proxy-agent. Covers fetch and axios.

One dispatcher

Set the global dispatcher once. Every route handler inherits it.

No infra surgery

No NAT gateway, no VPC changes, no custom networking. Just a runtime env var.

HTTPS-only

TLS passthrough. Your traffic is never decrypted or inspected by the proxy.

Production-ready

Starting from โ‚ฌ19/month. Flexible plans for every scale. Cancel anytime.

Get a Static IP for Your Next.js App

Stop fighting undici and rotating serverless IPs. Give your Next.js backend two fixed EU IPs today.

Frequently Asked Questions

Does Next.js fetch use HTTPS_PROXY automatically?

No. Next.js uses Node's native fetch, which is powered by undici, and undici does not read the HTTPS_PROXY environment variable. You have to register a proxy explicitly with undici's setGlobalDispatcher(new ProxyAgent(process.env.HTTPS_PROXY)). Once that runs, every server-side fetch in your App Router routes through OutboundGateway's two fixed EU IPs.

Does the proxy work in the Next.js Edge runtime?

The Edge runtime cannot import undici, so the ProxyAgent approach does not apply there. For outbound calls that must go through the proxy, keep those route handlers on the Node.js runtime. That is a real Next.js constraint, not a proxy limitation, and it is the main reason to prefer the Node runtime for IP-whitelisted partner calls.

Do Server Actions and route handlers share the same proxy?

Yes. Because the global undici dispatcher is process-wide, every server-side code path in your Next.js app, including Server Actions, route handlers, and getServerSideProps, uses it. You set it once and the whole backend egresses through the same two fixed static EU IPs, which is exactly what partner APIs expect.

Still Deciding?

We're happy to help you check whether OutboundGateway fits your Next.js workload.

Contact Our Team →