# Fix Vite "Blocked request. This host is not allowed"

> Vite answers `403 Blocked request. This host ("…") is not allowed.` when a request arrives with a `Host` header it doesn't recognize, such as a tunnel URL or a custom local domain. Add that hostname to `server.allowedHosts` in `vite.config.js` (or `preview.allowedHosts` for `vite preview`) and the request goes through. A leading dot, as in `.tunnl.gg`, allows every subdomain.

## The fix

```js
// vite.config.js or vite.config.ts
import { defineConfig } from 'vite'

export default defineConfig({
  server: {
    allowedHosts: ['.tunnl.gg'],
  },
})
```

Vite restarts the dev server when its config file changes; restart it by hand if it doesn't. `vite preview` uses the same list unless you set `preview.allowedHosts` separately.

To allow a single hostname rather than a whole domain, list it without the dot:

```js
server: {
  allowedHosts: ['brave-fox-7c41e09b.tunnl.gg'],
},
```

## The error

Opening the dev server through a tunnel without that setting gives a plain-text `403 Forbidden` page:

```text
Blocked request. This host ("brave-fox-7c41e09b.tunnl.gg") is not allowed.
To allow this host, add "brave-fox-7c41e09b.tunnl.gg" to `server.allowedHosts` in vite.config.js.
```

`vite preview` prints the same message with `preview.allowedHosts` in the second line. We reproduced both on Vite 8.3.8 by sending a spoofed `Host` header to a fresh `npm create vite` app.

## Why Vite blocks the host

The check was added in Vite 6.0.9, 5.4.12 and 4.5.6, released on January 20, 2025, as the fix for a security advisory ([GHSA-vg6x-rcgg-rjx6](https://github.com/vitejs/vite/security/advisories/GHSA-vg6x-rcgg-rjx6)). Before it, any website you visited could use DNS rebinding to send requests to your dev server and read the responses, including your source code. Rejecting unknown `Host` headers stops that.

The rules, from [Vite's docs](https://vite.dev/config/server-options#server-allowedhosts) and its source code:

- `localhost`, any name ending in `.localhost`, and every IP address are always allowed. That's why `http://localhost:5173` and `http://192.168.1.20:5173` work without config.
- An entry such as `example.com` matches only that exact hostname.
- An entry with a leading dot, such as `.tunnl.gg`, matches `tunnl.gg` and every subdomain of it.
- `preview.allowedHosts` defaults to `server.allowedHosts`.
- The hot reload WebSocket checks the same list, so an allowed host gets HMR too.

## Frameworks built on Vite

The message always says `vite.config.js`, even when your framework keeps Vite's settings somewhere else. We reproduced the error and the fix in each of these, except React Router, whose template we checked.

**SvelteKit** and **React Router** (framework mode) use a normal `vite.config.ts`, so the setting goes under `server` next to the plugin:

```ts
// vite.config.ts
import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [sveltekit()],
  server: {
    allowedHosts: ['.tunnl.gg'],
  },
})
```

**Nuxt** has no Vite config file; pass the setting through the `vite` key (tested with Nuxt 4.6):

```ts
// nuxt.config.ts
export default defineNuxtConfig({
  vite: {
    server: {
      allowedHosts: ['.tunnl.gg'],
    },
  },
})
```

**Astro** 5.4 and later have their own [`server.allowedHosts`](https://docs.astro.build/en/reference/configuration-reference/#serverallowedhosts) option (tested with Astro 7.4):

```js
// astro.config.mjs
import { defineConfig } from 'astro/config'

export default defineConfig({
  server: {
    allowedHosts: ['.tunnl.gg'],
  },
})
```

Vite 7 and later also read extra hosts from an environment variable, as a comma-separated list, which helps when you can't edit the config:

```bash
__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS=.tunnl.gg npm run dev
```

## Share the dev server through a tunnel

Start Vite, then open a tunnel to its port in a second terminal:

```bash
ssh -t -R 80:localhost:5173 stable@proxy.tunnl.gg
```

tunnl.gg prints a public HTTPS URL. `stable@` ties it to your SSH key, [registered to a free account](/stable-urls#register-your-key), so you get the same URL every time you reconnect; that means an allowlist entry for the exact hostname keeps working too. [How stable URLs work](/stable-urls).

If you'd rather not touch the config at all, have tunnl.gg send your app the `Host` header it expects:

```bash
ssh -t -R 80:localhost:5173 stable@proxy.tunnl.gg host=localhost
```

Vite then sees `localhost` and lets the request through. We tested both ways through a live tunnel, including the hot reload WebSocket.

The first time someone opens the link in a browser, tunnl.gg shows a warning page explaining that the site runs on someone's computer. They continue with one click, and won't see it again for a day, or a week on a stable URL. Free tunnels close after 2 hours idle or 24 hours in total; [Pro](/pricing) removes the warning page and the time limits.

## Hot reload over the tunnel

With the default config, the Vite client connects its HMR WebSocket to the same host and port the page came from, so through an HTTPS tunnel it uses `wss://` on port 443 and the edits you save show up for everyone viewing the link. tunnl.gg forwards WebSockets, so there's nothing to change.

If you have set `server.hmr` options such as `clientPort`, `host` or `protocol` for another setup, remove them while tunneling, or make them match the public URL (`protocol: 'wss'`, `clientPort: 443`). Vite's docs list those under [`server.ws`](https://vite.dev/config/server-options#server-hmr) in current versions.

## Why not `allowedHosts: true`?

`true` turns the check off for every hostname. Vite's documentation warns that it lets any website send requests to your dev server through DNS rebinding and read your source code and content. A tunnel doesn't need it: `.tunnl.gg` or your exact hostname is enough. Keep `true` for cases where something else already validates the `Host` header in front of Vite, and never leave it in a shared config by accident.

## Common questions

### Why does my local IP address work but the tunnel doesn't?

Vite always allows `localhost`, names under `.localhost` and any IP address. A tunnel URL is a hostname, so it has to be in `server.allowedHosts`, or the tunnel has to send `Host: localhost` to your app.

### Does the leading dot allow the bare domain too?

Yes. In Vite's check, `.tunnl.gg` matches `tunnl.gg` itself as well as any subdomain, such as `brave-fox-7c41e09b.tunnl.gg`.

### I added the host and still get the error. What now?

Restart the dev server by hand to be sure it picked up the change. Check that you edited the file your framework actually loads: `nuxt.config.ts` for Nuxt, `astro.config.mjs` for Astro, `vite.config.*` for SvelteKit and React Router. For `vite preview`, check that `preview.allowedHosts` isn't set to a different list.

### Do I need allowedHosts for a production build?

No. The check belongs to `vite` and `vite preview`. A production build is static files served by whatever server you deploy, which has its own host rules.

## Related

- [Share a local dev server](/guides/share-localhost-dev-server): the same fix for Next.js, webpack, Rails and Django
- [Next.js allowedDevOrigins](/guides/nextjs-allowed-dev-origins)
- [Stable URLs](/stable-urls)
- [tunnl.gg documentation](/docs)
