How to build and deploy nuxt?

I am not using one of the preconfigured deploy templates offered by many hosting services. Therefore I need to know how to traditionally build the site, deploy it, how to make sure https is enabled, and finally how to update it. Thanks.
2 Replies
kapa.ai
kapa.ai2w ago
Hi @Thick Black W. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To build and deploy a Nuxt application without using a preconfigured hosting template, follow these steps: --- 1. Build Your Nuxt Application Run the build command in your project directory:
nuxi build
nuxi build
This will generate a .output/ directory containing your production-ready server and assets. The main entry point for your server will be .output/server/index.mjs Nuxt Deployment Docs. --- 2. Deploy to Your Server - Copy the contents of your project (at least the .output/ directory and any required files like package.json) to your server. - Make sure Node.js is installed on your server. - Start your Nuxt server with:
node .output/server/index.mjs
node .output/server/index.mjs
By default, this will listen on port 3000. You can change the port and host using environment variables:
PORT=8080 HOST=0.0.0.0 node .output/server/index.mjs
PORT=8080 HOST=0.0.0.0 node .output/server/index.mjs
For process management and zero-downtime restarts, you can use PM2:
// ecosystem.config.cjs
module.exports = {
apps: [
{
name: 'NuxtAppName',
port: '3000',
exec_mode: 'cluster',
instances: 'max',
script: './.output/server/index.mjs'
}
]
}
// ecosystem.config.cjs
module.exports = {
apps: [
{
name: 'NuxtAppName',
port: '3000',
exec_mode: 'cluster',
instances: 'max',
script: './.output/server/index.mjs'
}
]
}
Then start with:
pm2 start ecosystem.config.cjs
pm2 start ecosystem.config.cjs
Nuxt Deployment Docs --- 3. Enable HTTPS Nuxt's Nitro server can serve HTTPS directly if you set the following environment variables: - NITRO_SSL_CERT (path or content of your SSL certificate) - NITRO_SSL_KEY (path or content of your SSL private key) If both are present, the server will run in HTTPS mode. However, the documentation strongly recommends using a reverse proxy (like nginx or Cloudflare) to terminate SSL in production, and only using Nitro's built-in HTTPS for testing Nuxt Deployment Docs. Example (not recommended for production):
NITRO_SSL_CERT=./cert.pem NITRO_SSL_KEY=./key.pem node .output/server/index.mjs
NITRO_SSL_CERT=./cert.pem NITRO_SSL_KEY=./key.pem node .output/server/index.mjs
For production, set up nginx or another reverse proxy to handle SSL and forward requests to your Nuxt server. --- 4. Update Your Application - Pull the latest code to your server. - Run nuxi build again to rebuild the .output/ directory. - Restart your server process (e.g., with pm2 restart NuxtAppName). --- Summary:
- Build with nuxi build. - Deploy .output/ to your server and run node .output/server/index.mjs. - Use a reverse proxy for HTTPS in production. - Rebuild and restart to update. If you need Docker deployment, there is an example Dockerfile in the docs. If you need static hosting, use nuxi generate instead of nuxi build Nuxt Deployment Docs. --- If you need more details on reverse proxy configuration or advanced deployment scenarios, the knowledge sources do not provide explicit step-by-step guides, but the above covers the standard traditional deployment process for Nuxt. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@1321238874634195004> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?