KloudiHub Docs
Sample

Deployment

Deploy your documentation site to production

Deployment

Learn how to deploy your documentation site to various platforms.

Vercel is the easiest way to deploy Next.js applications.

Install Vercel CLI

npm install -g vercel

Login to Vercel

vercel login

Deploy

vercel

Follow the prompts to complete deployment.

Auto Deployment

Connect your GitHub repository to Vercel for automatic deployments:

  1. Go to vercel.com
  2. Click "New Project"
  3. Import your Git repository
  4. Configure build settings (usually auto-detected)
  5. Click "Deploy"

Every push to your main branch will automatically trigger a new deployment.

Netlify

Install Netlify CLI:

npm install -g netlify-cli

Login:

netlify login

Deploy:

netlify deploy --prod
  1. Go to netlify.com
  2. Click "Add new site" → "Import an existing project"
  3. Connect your Git provider
  4. Select your repository
  5. Configure build settings:
    • Build command: npm run build
    • Publish directory: .next
  6. Click "Deploy site"

Cloudflare Pages

Connect Repository

  1. Go to Cloudflare Pages dashboard
  2. Click "Create a project"
  3. Connect your Git repository

Configure Build

Set the following build settings:

SettingValue
Framework presetNext.js
Build commandnpm run build
Build output.next
Node version18 or higher

Deploy

Click "Save and Deploy" to start the build process.

Make sure to set NODE_VERSION environment variable to 18 or higher.

Self-Hosting

Docker

Create a Dockerfile:

FROM node:18-alpine AS base

# Install dependencies
FROM base AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci

# Build app
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

# Production image
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]

Build and run:

docker build -t my-docs .
docker run -p 3000:3000 my-docs

Traditional Server

Build your application:

npm run build

Start the production server:

npm run start

Set up a reverse proxy (nginx example):

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;
    }
}

Environment Variables

Make sure to set required environment variables in your deployment platform.

Common variables:

# Required
NEXT_PUBLIC_SITE_URL=https://yourdomain.com

# Optional
NEXT_PUBLIC_ANALYTICS_ID=your-analytics-id
NODE_ENV=production

Static Export

Static export has limitations. Some Next.js features won't work.

Configure in next.config.mjs:

export default {
  output: 'export',
  images: {
    unoptimized: true,
  },
};

Build static site:

npm run build

The static files will be in the out directory.

Performance Optimization

Enable Caching

// next.config.mjs
export default {
  headers: async () => [
    {
      source: '/_next/static/:path*',
      headers: [
        {
          key: 'Cache-Control',
          value: 'public, max-age=31536000, immutable',
        },
      ],
    },
  ],
};

Compress Assets

Most platforms automatically compress assets. Verify in your platform settings.

Enable compression in your reverse proxy:

gzip on;
gzip_types text/plain text/css application/json application/javascript;
gzip_min_length 1000;

Monitoring

After deployment, monitor your site:

  • Uptime: Use services like UptimeRobot
  • Performance: Google PageSpeed Insights
  • Analytics: Google Analytics, Vercel Analytics
  • Errors: Sentry, LogRocket

On this page