Nuxt.js Deployment Options

Complete guide to deploying your Nuxt applications with step-by-step instructions

Nuxt 3 Deployment SSR Static

Introduction to Nuxt Deployment

Nuxt.js offers multiple deployment options depending on your application's requirements. The deployment method you choose depends on:

  • Rendering Mode: Static Site Generation (SSG), Server-Side Rendering (SSR), or Hybrid
  • Scalability Needs: Expected traffic and growth
  • Budget: Free vs paid hosting options
  • Technical Expertise: Server management vs managed services

This guide covers all major deployment options with detailed step-by-step instructions for each approach.

Static Hosting Options

For Nuxt applications using static site generation (SSG)

Vercel

Vercel (Static)

When to Choose:

  • Static generated Nuxt sites
  • Automatic preview deployments
  • Global CDN distribution

Step-by-Step Deployment:

  1. Prepare your Nuxt project:

    # Ensure your project is configured for SSG
    export default defineNuxtConfig({
      ssr: true, // For static generation
      nitro: {
        prerender: {
          routes: ['/sitemap.xml']
        }
      }
    })
  2. Build your project:

    npm run generate
    # Output will be in dist/ folder
  3. Sign up for Vercel at vercel.com

  4. Install Vercel CLI:

    npm install -g vercel
  5. Deploy from CLI:

    cd dist
    vercel deploy --prod
  6. Connect to GitHub (optional):

    Link your repo for automatic deployments on push

Configuration Tips:

  • Set VERCEL_ENV=production in environment variables
  • Configure redirects in vercel.json
  • Enable Automatic Static Optimization
Netlify

Netlify (Static)

When to Choose:

  • Simple static hosting
  • Forms and serverless functions
  • Git-triggered deployments

Step-by-Step Deployment:

  1. Configure Nuxt for SSG:

    // nuxt.config.ts
    export default defineNuxtConfig({
      ssr: true,
      nitro: {
        prerender: {
          crawlLinks: true
        }
      }
    })
  2. Build your project:

    npm run generate
  3. Sign up for Netlify at netlify.com

  4. Install Netlify CLI:

    npm install -g netlify-cli
  5. Deploy from CLI:

    cd dist
    netlify deploy --prod
  6. Configure build settings:

    Set build command to npm run generate and publish directory to dist

Configuration Tips:

  • Add _redirects file for SPA fallback
  • Configure form handling in Netlify dashboard
  • Set up deploy previews for PRs

Serverless Platforms

For Nuxt applications with server-side rendering or API routes

Vercel

Vercel (Serverless)

When to Choose:

  • SSR applications
  • API routes
  • Automatic serverless functions

Step-by-Step Deployment:

  1. Configure Nuxt for SSR:

    // nuxt.config.ts
    export default defineNuxtConfig({
      ssr: true,
      nitro: {
        // Serverless preset
        preset: 'vercel'
      }
    })
  2. Create vercel.json:

    {
      "version": 2,
      "builds": [
        {
          "src": "package.json",
          "use": "@vercel/static-build",
          "config": { "distDir": ".output/public" }
        }
      ],
      "routes": [
        { "handle": "filesystem" },
        { "src": "/.*", "dest": "/" }
      ]
    }
  3. Install Vercel CLI:

    npm install -g vercel
  4. Deploy:

    vercel
  5. Connect Git repository:

    Enable automatic deployments on push

Configuration Tips:

  • Use edge middleware for routes
  • Configure ISR for dynamic routes
  • Set proper cache headers
Netlify

Netlify (Serverless)

When to Choose:

  • SSR with Netlify Functions
  • Existing Netlify infrastructure
  • Form handling needs

Step-by-Step Deployment:

  1. Configure Nuxt:

    // nuxt.config.ts
    export default defineNuxtConfig({
      ssr: true,
      nitro: {
        preset: 'netlify'
      }
    })
  2. Create netlify.toml:

    [build]
      command = "npm run build"
      publish = ".output/public"
      functions = ".output/server/functions"
    
    [[redirects]]
      from = "/*"
      to = "/.netlify/functions/server"
      status = 200
  3. Install Netlify CLI:

    npm install -g netlify-cli
  4. Deploy:

    netlify deploy --prod
  5. Configure build settings:

    Set build command to npm run build

Configuration Tips:

  • Use Netlify Edge Functions for middleware
  • Configure form handling in dashboard
  • Set proper cache headers

Traditional SSR Hosting

For Node.js server deployments

Node.js Server

When to Choose:

  • Full control over server
  • Existing Node.js infrastructure
  • Custom server middleware

Step-by-Step Deployment:

  1. Configure Nuxt for SSR:

    // nuxt.config.ts
    export default defineNuxtConfig({
      ssr: true,
      nitro: {
        // No preset needed for Node
      }
    })
  2. Build your project:

    npm run build
  3. Prepare server:

    Ensure Node.js is installed on your server

  4. Install dependencies:

    npm install --production
  5. Start server:

    node .output/server/index.mjs
  6. Configure process manager (PM2 recommended):

    npm install -g pm2
    pm2 start .output/server/index.mjs --name "nuxt-app"

Configuration Tips:

  • Use reverse proxy (Nginx/Apache)
  • Configure logging and monitoring
  • Set up proper caching headers
Heroku

Heroku

When to Choose:

  • Easy Node.js hosting
  • Git-based deployments
  • Add-on ecosystem

Step-by-Step Deployment:

  1. Configure Nuxt for SSR:

    // nuxt.config.ts
    export default defineNuxtConfig({
      ssr: true,
      nitro: {
        // Heroku needs Node server
        preset: 'node'
      }
    })
  2. Create Procfile:

    web: node .output/server/index.mjs
  3. Set engine in package.json:

    "engines": {
      "node": "18.x"
    }
  4. Install Heroku CLI:

    npm install -g heroku
  5. Create Heroku app:

    heroku create
    git push heroku main
  6. Open app:

    heroku open

Configuration Tips:

  • Configure buildpacks for Node.js
  • Set up Heroku Redis for caching
  • Use Heroku Postgres for database

Containerization Options

For Docker-based deployments

Docker

Docker

When to Choose:

  • Consistent environments
  • Kubernetes deployments
  • CI/CD pipelines

Step-by-Step Deployment:

  1. Create Dockerfile:

    # Use Node.js base image
    FROM node:18-alpine as builder
    
    # Set working directory
    WORKDIR /app
    
    # Copy package files
    COPY package*.json ./
    
    # Install dependencies
    RUN npm install
    
    # Copy source files
    COPY . .
    
    # Build application
    RUN npm run build
    
    # Use minimal base image
    FROM node:18-alpine
    
    # Set working directory
    WORKDIR /app
    
    # Copy built files
    COPY --from=builder /app/.output /app/.output
    
    # Expose port
    EXPOSE 3000
    
    # Start application
    CMD ["node", ".output/server/index.mjs"]
  2. Build Docker image:

    docker build -t nuxt-app .
  3. Run container:

    docker run -p 3000:3000 nuxt-app
  4. Push to registry (optional):

    docker tag nuxt-app yourusername/nuxt-app
    docker push yourusername/nuxt-app

Configuration Tips:

  • Use multi-stage builds to reduce image size
  • Configure health checks
  • Set proper resource limits

Self-Hosting Options

For on-premise deployments

Nginx

Nginx Reverse Proxy

When to Choose:

  • On-premise deployments
  • High traffic applications
  • SSL termination

Step-by-Step Deployment:

  1. Install Nginx:

    # Ubuntu/Debian
    sudo apt install nginx
    
    # CentOS/RHEL
    sudo yum install nginx
  2. Configure Nginx:

    server {
        listen 80;
        server_name yourdomain.com;
        
        location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }
  3. Test configuration:

    sudo nginx -t
  4. Restart Nginx:

    sudo systemctl restart nginx
  5. Set up SSL (Let's Encrypt recommended):

    sudo apt install certbot python3-certbot-nginx
    sudo certbot --nginx -d yourdomain.com

Configuration Tips:

  • Enable gzip compression
  • Configure caching headers
  • Set up rate limiting
PM2

PM2 Process Manager

When to Choose:

  • Production Node.js process management
  • Zero-downtime reloads
  • Logging and monitoring

Step-by-Step Deployment:

  1. Install PM2 globally:

    npm install -g pm2
  2. Start Nuxt application:

    pm2 start .output/server/index.mjs --name "nuxt-app"
  3. Save process list:

    pm2 save
  4. Generate startup script:

    pm2 startup
  5. Monitor application:

    pm2 monit

Configuration Tips:

  • Use ecosystem file for advanced configuration
  • Set up log rotation
  • Configure cluster mode for multi-core servers

Deployment Option Comparison

Option Best For Pros Cons Difficulty
Vercel Static SSG sites, simple deployments Easy setup, global CDN, previews Limited SSR, vendor lock-in Beginner
Vercel Serverless SSR apps, API routes Automatic scaling, edge network Cold starts, cost at scale Intermediate
Netlify Static Marketing sites, forms Forms handling, easy CMS Slower builds, less flexible Beginner
Netlify Serverless SSR with functions Edge functions, forms Complex setup, cold starts Intermediate
Node.js Server Full control, custom needs Complete control, flexible Server management required Advanced
Docker CI/CD, Kubernetes Consistent environments Complexity, orchestration Advanced

Conclusion

Choosing the right deployment option for your Nuxt.js application depends on several factors:

  • For static sites: Vercel or Netlify provide the simplest and most effective solutions
  • For SSR applications: Vercel's serverless functions or traditional Node.js hosting
  • For maximum control: Docker containers or self-hosted Node.js with PM2
  • For enterprise needs: Kubernetes with Docker containers

Remember that you can change deployment strategies as your application grows. Many teams start with simple static hosting and migrate to more complex solutions as their needs evolve.

Final Tip: Always test your deployment pipeline thoroughly and consider implementing a staging environment before deploying to production.

Frequently Asked Questions

Which deployment option is best for SEO?

For best SEO results, use either static generation (for content that doesn't change frequently) or SSR (for dynamic content). Vercel and Netlify both offer excellent solutions for SEO-optimized deployments.

How do I handle environment variables in different deployments?

Most platforms provide ways to set environment variables. For Vercel/Netlify, use their dashboards. For Docker, use .env files or runtime arguments. For Node.js servers, use process.env with proper configuration management.

Can I switch between deployment options later?

Yes, but some changes may require code adjustments. Moving from static to SSR typically requires the most changes, while switching between similar platforms (like Vercel to Netlify) is usually straightforward.