A plain Vue single-page app builds to static files, so any Ubuntu server can host it with Nginx and a free Let’s Encrypt certificate. No Node process runs in production. An SSR app, such as Nuxt in server mode, is different: it needs a running Node process behind Nginx.
This guide walks through both paths. You will set up an Ubuntu server, build a Vue 3 app with Vite, serve it with Nginx, fix Vue Router 404s on refresh, add SSL and security headers, run a Nuxt or Express backend under systemd, and automate deploys with GitHub Actions and rsync. It ends with how an AI agent can do the deployment for you.
Deploying on your own Ubuntu server gives you control over the web server, caching and cost. If you are still choosing between a server and a managed host, how to choose a host for an app an AI wrote covers the trade-offs. The same steps work for other frameworks too, see the same approach for React.
What Vue Needs From a Host
Vue apps have a few traits that decide how you host them:
- Vue Router in history mode: the server must send
index.htmlfor any path that is not a real file, or refreshing/dashboardreturns a 404. - Hashed build output: Vite writes files like
assets/index-3f9a1c.js, so you can cache them for a long time and still ship updates. - Environment variables at build time:
VITE_variables are baked into the bundle when you runnpm run build, not read at runtime. - An optional API: if your app talks to a backend, Nginx can proxy
/api/to it on the same domain.
Deploy Your Vue App on an Ubuntu Server
Step 1: Ubuntu Server Setup
# Update system and install Node.js (needed to build, not to serve a SPA)
sudo apt update && sudo apt upgrade -y
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install nginx for serving static files
sudo apt install nginx -y
# Install certbot for SSL certificates
sudo apt install certbot python3-certbot-nginx -y
# Install git for deployment
sudo apt install git -y
Step 2: Prepare Your Vue Application
# Create a new Vue 3 application
npm create vue@latest my-vue-app
cd my-vue-app
npm install
# Build for production
npm run build
The build writes everything to the dist/ folder. That folder is all Nginx needs to serve.
Step 3: Deploy to the Server
# Clone the repo and build on the server
git clone https://github.com/yourusername/my-vue-app.git /var/www/my-vue-app
cd /var/www/my-vue-app
npm ci
npm run build
# Set proper ownership
sudo chown -R www-data:www-data /var/www/my-vue-app
Use npm ci and not npm ci --production. Vite and the Vue plugin are dev dependencies, and the build fails without them.
You can also build on your own machine and copy dist/ up with rsync -az --delete dist/ user@your-server:/var/www/my-vue-app/dist/. The CI section below automates that.
Step 4: Configure Nginx for a Vue SPA
sudo nano /etc/nginx/sites-available/my-vue-app
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/my-vue-app/dist;
index index.html;
# Vue Router history mode: fall back to index.html
location / {
try_files $uri $uri/ /index.html;
}
# Long cache for hashed assets
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# Optional: proxy API calls to a backend on port 3001
location /api/ {
proxy_pass http://localhost:3001/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json image/svg+xml;
}
# Enable the site and get an SSL certificate
sudo ln -s /etc/nginx/sites-available/my-vue-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Certbot edits the server block to add HTTPS and sets up automatic renewal. Point your domain’s DNS A record at the server’s IP before you run it.
Vue 3 Production Setup
Environment Configuration
Vite reads .env.production when you build:
# .env.production
VITE_APP_API_URL=https://api.yourdomain.com
VITE_APP_TITLE=My Vue App
// src/config/index.js
export const config = {
apiUrl: import.meta.env.VITE_APP_API_URL,
title: import.meta.env.VITE_APP_TITLE,
isProd: import.meta.env.PROD
}
Anything prefixed with VITE_ ends up in the public bundle. Never put secrets there.
Route-Based Code Splitting
Lazy-load each route so visitors only download the code for the page they open:
// src/router/index.js
import { createRouter, createWebHistory } from 'vue-router'
const routes = [
{ path: '/', name: 'Home', component: () => import('../views/Home.vue') },
{ path: '/dashboard', name: 'Dashboard', component: () => import('../views/Dashboard.vue') },
{ path: '/profile/:id', name: 'Profile', component: () => import('../views/Profile.vue') }
]
export default createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes
})
A Minimal Vite Config
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
export default defineConfig({
plugins: [vue()],
build: {
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vendor: ['vue', 'vue-router', 'pinia']
}
}
}
},
resolve: {
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) }
},
server: {
// Local dev only: forward /api to your backend
proxy: { '/api': { target: 'http://localhost:3001', changeOrigin: true } }
}
})
A Hardened Nginx Config for Production
Once Certbot has issued a certificate, you can tighten the server block. This version redirects HTTP to HTTPS, adds HSTS, keeps index.html uncached so new releases show up, and rate limits the API.
# /etc/nginx/conf.d/rate-limit.conf (http context, one line)
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
# /etc/nginx/sites-available/my-vue-app
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
http2 on;
server_name yourdomain.com www.yourdomain.com;
root /var/www/my-vue-app/dist;
index index.html;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# index.html must not be cached, or users keep an old bundle reference
location = /index.html {
add_header Cache-Control "no-cache";
}
location / {
try_files $uri $uri/ /index.html;
}
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://localhost:3001/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript image/svg+xml;
}
Add a Content-Security-Policy header only after testing it in your browser console. A policy that is too strict blocks your own scripts, and Vue apps that use inline styles or runtime template compilation need extra allowances. Brotli needs an extra Nginx module, so gzip is the safe default.
Server-Side Rendering With Nuxt
If you need server-rendered pages for SEO, use Nuxt in its default server mode. It builds to a Node server, so you run it as a service and put Nginx in front.
npx nuxi init my-nuxt-app
cd my-nuxt-app
npm install
npm run build
# Starts the server on port 3000
node .output/server/index.mjs
Run it under systemd so it restarts on failure and on reboot:
# /etc/systemd/system/my-nuxt-app.service
[Unit]
Description=My Nuxt app
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/my-nuxt-app
Environment=PORT=3000
Environment=NODE_ENV=production
ExecStart=/usr/bin/node .output/server/index.mjs
Restart=on-failure
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now my-nuxt-app
In Nginx, replace the static location / block with a proxy to http://localhost:3000, using the same proxy headers as the /api/ block above. If you only need Nuxt to produce static files, npx nuxi generate writes a static site you can serve exactly like the SPA above. For more on running Node processes on a server, see the Node.js hosting guide.
Vue With an Express API Backend
You can serve the built SPA and the API from one Express process:
// server/index.js
const express = require('express')
const history = require('connect-history-api-fallback')
const app = express()
// API routes
app.use('/api', require('./routes/api'))
// Serve the Vue app
app.use(history())
app.use(express.static('dist'))
const PORT = process.env.PORT || 3000
app.listen(PORT, () => console.log(`Server running on port ${PORT}`))
Run it with a systemd unit like the Nuxt one above, with ExecStart=/usr/bin/node server/index.js. Nginx then proxies everything to that port. Keeping the SPA on Nginx and only /api/ on Node is usually simpler and lets Nginx serve static files directly.
Vue Security Practices
Sanitize HTML You Render
Vue escapes text by default. v-html does not, so sanitize anything that comes from users:
// src/utils/security.js
import DOMPurify from 'dompurify'
export const sanitizeHTML = (dirty) =>
DOMPurify.sanitize(dirty, {
ALLOWED_TAGS: ['b', 'i', 'em', 'strong', 'a'],
ALLOWED_ATTR: ['href']
})
<script setup>
import { computed } from 'vue'
import { sanitizeHTML } from '@/utils/security'
const props = defineProps(['content'])
const sanitizedContent = computed(() => sanitizeHTML(props.content))
</script>
<template>
<div v-html="sanitizedContent"></div>
</template>
Keep Tokens Out of localStorage When You Can
Any script on the page can read localStorage, so an XSS bug exposes the token. Prefer HttpOnly cookies set by your API, and call it with withCredentials: true:
// src/services/api.js
import axios from 'axios'
export default axios.create({
baseURL: import.meta.env.VITE_APP_API_URL,
timeout: 10000,
withCredentials: true
})
Other Basics
- Serve everything over HTTPS and redirect HTTP.
- Keep dependencies updated and run
npm auditin CI. - Never commit
.envfiles or put secrets inVITE_variables. - Expose only ports 22, 80 and 443 with the Ubuntu firewall (
ufw).
CI/CD: Build in GitHub Actions, Deploy With rsync
This workflow builds the app on every push to main and copies dist/ to your server over SSH. Add SSH_HOST, SSH_USER and SSH_KEY as repository secrets. SSH_KEY is a private key whose public half is in the server user’s authorized_keys, and that user needs write access to the target folder.
# .github/workflows/deploy-vue.yml
name: Deploy Vue
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm run test:unit
- run: npm run build
- name: Copy dist to the server
env:
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }}
run: |
mkdir -p ~/.ssh
echo "$SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H "$SSH_HOST" >> ~/.ssh/known_hosts
rsync -az --delete dist/ "$SSH_USER@$SSH_HOST:/var/www/my-vue-app/dist/"
Remove the test:unit line if your project has no such script. Nginx serves the new files immediately, so no reload is needed for a static SPA.
Troubleshooting Common Vue Hosting Issues
404 Errors on Page Refresh
This is the most common problem. Vue Router in history mode handles /dashboard in the browser, but on refresh the request reaches Nginx, which looks for a file called dashboard. Fix it with the fallback in your server block:
location / {
try_files $uri $uri/ /index.html;
}
If you cannot change the server, switch to createWebHashHistory(), which keeps routes after a # and needs no server rule. Hash URLs are worse for sharing and SEO, so prefer the fallback.
Large Bundle Size
Look at what is in the bundle before changing anything:
npm install -D rollup-plugin-visualizer
// vite.config.js
import { visualizer } from 'rollup-plugin-visualizer'
export default defineConfig({
plugins: [vue(), visualizer({ open: true })]
})
Then lazy-load heavy routes and import only the components you use from UI libraries.
Slow Initial Load
Make sure gzip is on, assets under /assets/ are cached, and large images are compressed before you commit them. Lazy-loaded routes keep the first download small. If your API is on another domain, a <link rel="preconnect" href="https://api.yourdomain.com"> in index.html saves a connection round trip.
Blank Page After Deploy
Open the browser console. A 404 on /assets/... usually means the root path in Nginx points at the wrong folder. A blank page with a MIME type error often means the app is served from a sub-path: set base in vite.config.js to match.
Vue Deployment Checklist
Before Deploying
-
npm run buildsucceeds locally - Environment variables are set in
.env.production - No secrets in
VITE_variables - Production build tested with
npm run preview
Server Configuration
-
try_filesfallback toindex.htmlis in place - SSL certificate issued and renewal works (
sudo certbot renew --dry-run) - Security headers set
- Firewall allows only SSH, HTTP and HTTPS
After Deploying
- Refresh a deep route such as
/dashboardand confirm it loads - Check the browser console for errors
- Test API calls from the live domain
- Confirm HTTP redirects to HTTPS
Deploy a Vue App From Your AI Agent With CloudPloy
If you would rather not run these commands by hand, CloudPloy lets an AI agent do the deployment. You add the CloudPloy MCP server to Claude Code, Cursor, ChatGPT or any MCP client:
claude mcp add --transport http cloudploy https://brain.cloudploy.com/mcp
Sign in in the browser (OAuth, no token to paste), then connect your own server: an AWS EC2 instance in your account, or any server reachable over SSH. Ask the agent to deploy the repo. CloudPloy builds with Nixpacks, sets up SSL and does zero-downtime deploys. See the MCP setup docs for the full flow and pricing for the free plan limits. The server bill goes to your cloud provider.
One honest note: a pure static Vue site does not need any of this, and a static host can be simpler. A server makes sense when you also run an API, an SSR app or other services on the same machine.
FAQ
How do I host a Vue app on my own server?
Run npm run build, copy the dist/ folder to the server, and serve it with Nginx using a try_files $uri $uri/ /index.html; rule. Add a free certificate with Certbot for HTTPS. The steps above cover each command.
Why do I get a 404 when I refresh a Vue Router page?
With history mode, routes like /dashboard only exist in the browser. On refresh, the server looks for a real file and finds none. Add try_files $uri $uri/ /index.html; to your Nginx location / block so unknown paths return index.html.
Do I need Node on the server for a Vue SPA?
No. You need Node to build the app, and you can do that on your laptop or in CI. In production the server only serves the static files in dist/. SSR frameworks like Nuxt in server mode are the exception, because they run a Node process.
Can an AI agent deploy my Vue app?
Yes. With an MCP server connected, an agent such as Claude Code can create the app, deploy it and read logs for you. Deploying from Claude Code over MCP shows the full flow.
Updated November 19, 2026. Vue.js is a trademark of Yuxi (Evan) You.