nuxt.config.ts file. If not all pages are prerendered, you should use Application Hosting; otherwise, you should use Static Site Hosting.
Application Hosting
Choose Application Hosting (Server-Side Rendering) when your application requires server-side logic or dynamic behavior that static files cannot provide. SSR is ideal when your site includes:- Personalized user experiences, such as dashboards and profiles.
- Real-time or frequently changing data that must be fetched on every request.
- Dynamic routes that cannot be known ahead of time, making static pre-rendering impractical.
- Authentication-dependent content, where access and rendering vary based on the user’s session or permissions.
Configuration
To configure your Nuxt application for Sevalla, we recommend you follow these best practices:- Use Nitro’s built-in caching (
defineCachedEventHandler) for expensive operations. - Apply Nuxt Route Rules for static generation and edge caching.
- Use Nuxt Image for optimized image delivery.
- Enable compression in your Nitro config.
- Prerender pages that don’t require SSR.
runtimeConfig for handling environment variables, ensuring they are properly injected and kept server-only unless explicitly exposed.
The following is an example nuxt.config.ts file for deploying a Nuxt.js app on Sevalla:
Containerization
Dockerfile
The build for Dockerfiles is fully customizable. The following is an example Dockerfile for Nuxt.js:Nixpacks
You can customize the Nixpacks build process by defining anixpacks.toml file and using Nixpacks-specific environment variables. This allows you to fine-tune how dependencies are installed, how your application is built, and which runtime settings are applied.
The following is an example nixpacks.toml configuration:
NIXPACKS_NODE_VERSIONenvironment variable.
Buildpacks
If you’re using Buildpacks, you cannot modify the underlying build phases directly or control dependencies. You must rely on the runtime environment that Buildpacks detects. You can influence the build process by adjusting thebuild script in your package.json. Buildpacks will run whatever command you specify under the build script. For example, the standard command used to compile a Nuxt.js application is:
CDN
Sevalla provides a premium, Cloudflare-powered CDN for Application Hosting at no additional cost. To get the most out of Sevalla’s CDN when deploying your Nuxt.js application, we recommend the following best practices:- Enable the CDN for all production applications to ensure global, low-latency delivery.
- Use the
<NuxtImg>component for automatic image optimization and responsive formats. - Set appropriate
Cache-Controlheaders on API routes to ensure proper caching behavior. - Purge CDN cache after critical deployments to ensure users receive updated content.
- Rely on Nuxt’s versioned assets in the
_nuxt/directory, which are safe to cache indefinitely. - Store static files in the
public/directory, allowing the CDN to serve them efficiently.
Edge caching
Edge caching stores your Sevalla site cache on Cloudflare’s 260+ global data centers, delivering responses from the location nearest to each visitor for faster performance. To maximize the benefits of Sevalla’s Edge Caching for your Nuxt.js application, we recommend the following best practices:- Set appropriate
Cache-Controlheaders on server-rendered pages to control caching behavior. - Combine edge caching with the CDN to cover both dynamic and static assets.
- Monitor cache efficiency using the
cf-cache-statusheader returned by Cloudflare.
Cache-Control
With Sevalla’s Cloudflare integration, Cache-Control headers are respected at the edge, giving you precise control over how content is cached and served globally. The following are some common directives you can use in your Nuxt.js application:
public, s-maxage=3600- Caches the response on the CDN for 1 hour, improving performance for frequently accessed content.public, max-age=31536000, immutable- Ideal for versioned static assets (e.g., files in.output/public/_nuxt/), allowing them to be cached for up to 1 year with no revalidation.private- Prevents CDN caching and ensures the response is only cached by the end user’s browser, for personalized or sensitive data.
Sevalla does not yet support the
stale-while-revalidate Cache-Control directive. To prevent unexpected caching behavior, we recommend not using this directive in your API or asset caching settings.Server route caching with Nitro
Nuxt.js uses Nitro’s caching capabilities for server routes:Route rules for page caching
You can use route rules to cache specific pages:Cache Invalidation
Nuxt.js provides cache invalidation through Nitro’s storage layer: Clear specific cache entry:Health checks
Ensure your application remains available during deployments by implementing health checks:- Always implement health checks for production applications.
- Keep checks lightweight; responses should complete in under 1 second.
- Verify critical dependencies (e.g., databases, Redis) as part of the checks.
- Return 200 for degraded states to allow deployments to continue smoothly.
- Return 503 only for critical failures that require pod restarts.
- Close connections cleanly (e.g., database pools, Redis) to prevent resource leaks.
- Test deployments in staging with monitoring scripts to validate health checks.
Multi-tenancy
Sevalla fully supports multi-tenancy. You can build multi-tenant Nuxt.js applications using wildcard domains, allowing you to serve multiple tenants from separate subdomains efficiently and securely. Use the following best practices for multi-tenancy on Sevalla with your Nuxt.js application:- Use wildcard domains to serve subdomain-based tenants (e.g.,
tenant1.app.com). - Add custom domains individually for tenants who have their own domains.
- Cache tenant data to reduce database queries and improve performance.
- Validate tenant existence before rendering pages to prevent errors or unauthorized access.
- Isolate tenant data in the database using separate schemas or a
tenant_idcolumn. - Leverage free SSL certificates, which are automatically provided for both wildcard and custom domains.
Nuxt.js multi-tenant implementation
Below is a reference architecture for extracting tenant information from the hostname and injecting it into Nuxt’s request lifecycle. Extract tenant from subdomain using middleware:Custom domains per tenant
Allow tenants to use their own domains (e.g.,customdomain.com → tenant data).
Map custom domains to tenants:
Static Site Hosting
Static Site Generation (SSG) pre-renders all pages as static HTML files at build time, delivering fast and reliable performance. Use SSG when your site includes:- Content that changes infrequently, such as blog posts, documentation, or product catalogs.
- Pages that can be pre-rendered for all users without personalization.
- Requirements for maximum performance and minimal hosting costs.
- A global audience, as static pages benefit from fast CDN distribution.
Configuration
Usenuxt generate to build and prerender your application using Nitro’s crawler. This command is similar to running nuxt build with nitro.static enabled (or nuxt build --prerender).
During generation, Nuxt builds your site, starts a temporary server, and automatically crawls pages beginning with / pre-rendering every reachable route.
.output/public to any static hosting provider, or preview the result locally using:
Redirects
To apply custom redirect rules, add a_redirects file containing your redirects to your repository’s root directory. Sevalla will automatically parse the file’s contents and apply the custom redirect rules.