---
title: "Runtime Site Config · Nuxt Site Config · Nuxt SEO"
canonical_url: "https://nuxtseo.com/docs/site-config/guides/runtime-site-config"
last_updated: "2026-08-14T21:00:59.891Z"
meta:
  description: "Learn how to set site config at runtime in your Nuxt app."
  "og:description": "Learn how to set site config at runtime in your Nuxt app."
  "og:title": "Runtime Site Config · Nuxt Site Config · Nuxt SEO"
---

Nuxt SEO on GitHub

Switch to Site ConfigSwitch to Nuxt SEOSwitch to RobotsSwitch to SitemapSwitch to OG ImageSwitch to Schema.orgSwitch to Link CheckerSwitch to SEO UtilsSwitch to Skew ProtectionSwitch to AI Ready

**Core Concepts**

# **Runtime Site Config**

Site config can be set from many different sources from each environment.

The most flexible way to set your site config is at runtime. This gives you the ability to set it based on any condition you want, even allowing [**~~multi-tenancy~~**](https://nuxtseo.com/docs/site-config/guides/multi-tenancy).

## Caveats

When setting site config at runtime, it's important to set it as early as possible on the server.

This is because modules will be using site config to generate your app. For example, if you're using Nuxt SEO, site config drives `**sitemap.xml**` and `**robots.txt**` generation.

Therefore, it's recommended to set it either within a Nitro plugin or middleware.

## Plugin

A Nitro plugin is useful when you want to set site config based on a static condition, such as the environment or based on a result from a database.

Because Site Config is attached to an H3 Request context, you will need to use the `**site-config:init**` hook to set it.

For example, here we are setting site config based on a database query:

server/plugins/update-site-config-from-db.ts

```ts
export default defineNitroPlugin(async (nitroApp) => {
  const site = await $fetch('/db/site-config', {
    params: { env: import.meta.env.NUXT_SITE_ENV },
  })
  nitroApp.hooks.hook('site-config:init', ({ event, siteConfig }) => {
    siteConfig.push(site)
  })
})
```

## Middleware

If you prefer a simpler API, you can use a Nitro middleware instead with `**updateSiteConfig**` function.

For example, here we are setting site config based on an admin host:

server/middleware/update-site-config.ts

```ts
import { getNitroOrigin, updateSiteConfig } from '#site-config/server/composables'

export default defineEventHandler((e) => {
  const origin = getNitroOrigin(e)
  if (origin.startsWith('https://admin.')) {
    updateSiteConfig(e, {
      name: 'Admin',
      indexable: false,
      url: 'https://admin.example.com'
    })
  }
})
```

**Was this page helpful?**

### **Related **

[**Multi-Tenancy**](https://nuxtseo.com/docs/site-config/guides/multi-tenancy)

[**updateSiteConfig()**](https://nuxtseo.com/docs/site-config/nitro-api/update-site-config)

[**Understanding Site Config**](https://nuxtseo.com/docs/nuxt-seo/guides/site-config)

[**How it works** Learn how the Nuxt Site Config module works, so you can get the most out of it.](https://nuxtseo.com/docs/site-config/guides/how-it-works) [**Multi-Tenancy** Learn how to serve multiple sites with different configurations based on the hostname.](https://nuxtseo.com/docs/site-config/guides/multi-tenancy)