Skip to content
Guides

How to deploy a Next.js app to production with your domain and SSL

By · Quimera Group

Updated on

You have a Next.js app and you want to see it at https://your-domain.com, with the padlock and without building the server yourself. This guide takes you from next build to your domain with SSL, on QuimeraCloud’s Cloud Startup plan. The idea is simple: Next.js produces a minimal server, NodeApp starts it with PM2, nginx receives your domain’s visits and passes them to your app, and the Let’s Encrypt SSL is free. If you first want to see what the service includes, it is summarized in Next.js and Node.js hosting. If your app is plain Node.js without Next.js, the base guide is deploy a Node.js app with a domain and SSL.

What you need before you start

Item Cloud Startup
Node.js apps and SSH access Included (jailed shell, no root)
Cores and memory 4 cores and 4 GB of RAM
Disk 100 GB SSD
Launch price US$9.99 a month the first year, billed annually
Renewal US$311.88 a year (US$25.99 a month)
Month to month US$27.99
  • Plan. Only Cloud Startup has SSH and Node.js apps. Payment is by credit or debit card through Stripe, in US$.
  • Node.js 20 or 22. Current Next.js versions require Node.js 20.9 or later (per their installation page). The server has Node.js 16, 18, 20 and 22 installed with NVM; you will use 22.
  • Domain. One you already own or a new one. The steps to point it are in how to point a .com or .bo domain to your hosting.
  • Your Next.js project in a Git repository.

How the pieces fit

One detail is worth understanding before you touch anything: NodeApp and Next.js receive the port in different ways.

Piece What it does
NodeApp Starts your app with PM2 and passes the port as the argument -p <port>, according to its nodeapp.js.
Next.js standalone server Reads the port and address from the PORT and HOSTNAME variables, according to the Next.js documentation.
A short app.js Turns NodeApp’s -p into PORT and HOSTNAME. You write it in step 4.
nginx Receives your domain and passes it to 127.0.0.1 and your app’s port (as the plugin’s nodeapp.php defines it). The Next.js documentation itself recommends putting a reverse proxy such as nginx in front.

Step by step

1. Prepare your project

In next.config.js (or next.config.mjs) turn on standalone mode:

// next.config.js
module.exports = {
  output: 'standalone',
};

With that option, next build creates the .next/standalone folder, which according to the documentation can be deployed on its own, without installing node_modules. The server’s Node version is not set here but in the .nvmrc file of the nodeapp folder (step 2).

2. Turn on NodeApp for your domain

  1. Log in to the panel (available in Spanish, Portuguese, French, Italian, German and English).
  2. On the Web tab, add your domain or edit it and open the advanced options (Advanced Options).
  3. Pick NodeApp in the list of proxy templates (Proxy Template) and save.

The plugin requires your user to have SSH access; on QuimeraCloud, Cloud Startup includes it. If you do not see NodeApp among the templates, message us on WhatsApp. Once saved, web/<domain>/nodeapp contains an example app with app.js, app.config.js and .nvmrc: keep app.config.js and .nvmrc. The .nvmrc has a single line with the Node version (v22); if you prefer 20, change it to v20.

3. Build on Linux

Build on a Linux system, not on Windows or macOS: standalone mode copies only the modules your app uses, and native ones (for example sharp, used by next/image) stay compiled for the system where you build. The simplest way is to build on the server itself, over SSH, with your repository outside the nodeapp folder:

source /opt/nvm/nvm.sh && nvm use 22   # NodeApp uses NVM in /opt/nvm
git clone https://github.com/your-user/your-app.git ~/your-app   # first time only
cd ~/your-app
git pull
npm ci
npm run build                          # runs next build

Then copy into .next/standalone the two folders that the minimal server does not include by default (as the Next.js documentation states):

cp -r public .next/standalone/
cp -r .next/static .next/standalone/.next/

If your shell cannot find node or npm, message us on WhatsApp. If the build runs out of memory, build it on your own Linux computer or on a Linux continuous integration service and upload the result over SSH.

4. Put the standalone server in nodeapp

Copy the whole content of .next/standalone into your domain’s nodeapp folder. Do not delete app.config.js or .nvmrc: standalone does not include them, so the copy does not overwrite them.

cp -a .next/standalone/. ~/web/your-domain.com/nodeapp/

Now replace the example app.js with this one, which turns NodeApp’s port (-p) into the variables Next.js reads:

// ~/web/your-domain.com/nodeapp/app.js
const i = process.argv.indexOf('-p');
const port = i > -1 ? process.argv[i + 1] : '';
if (!port) {
  console.log('Port number is not specified');
  process.exit(1);
}
process.env.PORT = port;
process.env.HOSTNAME = '127.0.0.1';   // nginx reaches it through 127.0.0.1
require('./server.js');

It needs neither express nor minimist. The example app.config.js already points to app.js and picks the Node version from .nvmrc; you do not need to touch it.

5. Start it with PM2 and check the logs

From the nodeapp folder, over SSH:

cd ~/web/your-domain.com/nodeapp
pm2 start app.config.js    # starts with PM2
pm2 logs                   # live logs

You can also start, stop, restart and view logs from the NodeApp process list in the panel (Web tab). On each new deploy repeat steps 3 and 4 and restart the app with touch .restart/restart or from the panel.

About pm2 startup and pm2 save: the PM2 documentation uses them to start your processes again after the server reboots, and pm2 startup generates a command that runs with administrator permissions. In NodeApp, the plugin’s README describes its own action that restarts PM2 apps after a server reboot, so you do not need to do it yourself.

6. Point your domain

There are two ways, and the domain guide has the steps for each: change the nameservers to ns1.quimeracloud.com and ns2.quimeracloud.com, or edit your current DNS’s A record to the server’s IPv4. That IP is shared and we do not publish it in the guide: confirm it with the team on WhatsApp before editing anything.

7. Turn on SSL and check

Let’s Encrypt SSL is free and renews itself. To issue it, Let’s Encrypt checks that you control the domain by requesting a file over HTTP on port 80 (documentation), so the domain must already reach our server.

  1. Open http://your-domain.com and check that it shows your app.
  2. In the panel, open your domain’s options and tick the SSL and Let’s Encrypt boxes (Enable SSL for this domain and Use Let’s Encrypt to obtain SSL certificate). Save. The HestiaCP documentation describes it this way.
  3. Open https://your-domain.com and check the padlock.

Limits worth knowing

  • One server, in Seattle (US). There is no edge network and no replicas.
  • No root. You cannot install system software. If your app needs that, a VPS fits better: we compare them in shared, cloud or VPS hosting.
  • Disk cache. By default Next.js keeps its cache on the server’s disk; with a single server it works without configuration.
  • Images. next/image optimization runs on your server and uses memory.
  • MySQL/MariaDB only as included databases.

Common problems

What you see Likely cause What to do
The log says “Port number is not specified” The app started without the -p argument Start it with pm2 start app.config.js or from the panel, not with node app.js by hand
502 error when opening the domain The app is not listening on the port nginx expects Check that app.js sets PORT and HOSTNAME before require('./server.js')
The page loads without styles or images public and .next/static were not copied into standalone Repeat the two cp -r commands from step 3 and restart
Native module errors (for example sharp) You built on a different operating system Build on Linux, as in step 3
You changed the code and nothing changes The app is still running the old version Restart with touch .restart/restart

If something does not match what you see in your panel, message us on WhatsApp at +591 773 14890: a person on the Quimera team answers, 24 hours a day. And if you are still choosing, compare the plans.

Frequently asked questions

Can I use next start instead of standalone mode?

Yes, it is possible, but this guide uses standalone because it produces a minimal server (server.js) that deploys without installing all of node_modules on the server. With next start you need the whole project and its dependencies installed in the nodeapp folder.

Which Node.js version should I use for Next.js?

Current Next.js versions require Node.js 20.9 or later. The server has Node.js 16, 18, 20 and 22 through NVM, so pick 20 or 22 with an .nvmrc file inside your domain's nodeapp folder, for example with the line v22.

Does next/image optimization work?

It works on your own server, but it uses memory. The Next.js documentation warns that on glibc-based Linux it may need extra configuration to prevent excessive memory use. If you do not need it, turn it off in next.config with images.unoptimized or use an external image service.

Is there automatic deployment on git push?

No. You run git pull, build, copy the result and restart the app over SSH, or you automate those steps with a script. If you need a deploy on every commit, platforms such as Vercel or Render include it.

Which database can I use with my Next.js app?

The plans include MySQL/MariaDB, with 300 databases on Cloud Startup. Other database engines are not included. If your app depends on a different one, a VPS fits better, where you install whatever you need.

Sources

All guides

Launch your site this week

Pick your plan, connect your domain and get started. If you have questions before you buy, message us.