On this page

Deployment

With Pruvious' CLI, you can deploy your website to multiple remote servers using a single command. You can also create backups, restore them, and mirror content between a live site and your local environment.


Server setup

Pruvious provides a bash script for conveniently setting up a remote server, allowing you to deploy your website with just one command. It currently supports Ubuntu versions 20.04 and 22.04.

To set up a server, simply run the following command as a sudo user on your server:

# Terminal

curl -sLo tmp.sh https://pruvious.com/ubuntu-setup.sh && bash tmp.sh && rm tmp.sh

The script will perform the following tasks:

  • Create a new user named pruvious and add it to the sudo group.

  • Install packages needed for running Nuxt and Pruvious.

  • Configure the firewall to allow SSH, HTTP, and HTTPS traffic.

DigitalOcean

We suggest starting with a basic DigitalOcean droplet of your preferred size. You can use the link below to receive a $200 credit for 60 days:

Create an account on DigitalOcean.

After creating your account and a droplet, log in to your server as the root user using SSH or the integrated console. Then, execute the ubuntu-setup.sh script as demonstrated in the example above. Once the setup is complete, you will see a command displayed in the following format:

# Terminal

npx pruvious servers add --host={host} --name={name} --private-key='{key}'

Run this command in your local project to add the server. Afterward, you can find all registered servers in the .ssh.ts file located in the root directory of your project.

Website domain

Once you have set up the server, the next step is to register a domain name and point the A records (both www and non-www) to your server's IP address. You can find instructions on how to do that in your preferred registrar's documentation or on various sources online.

After the domain has propagated, add the site to your project by running the following command locally:

# Terminal

## pnpm
pnpm exec pruvious sites add

## npm
npx pruvious sites add

This command will prompt you for necessary details and automatically set up and configure the site on your server. If you want to use a subdomain without the www prefix, use the --no-www flag in the command.

Deployment

To push your current project to a remote server, use the following command in your local project:

# Terminal

## pnpm
pnpm exec pruvious deploy

## npm
npx pruvious deploy

This command will prompt you to choose a server and site (domain name). It will then upload your project and start the Node.js process remotely. Your website should now be online and accessible via the selected domain.

Content mirroring

To ensure that a newly deployed site appears identical to your local environment, you must transfer both the database and uploads to the server. To accomplish this, execute the following command within your local project:

# Terminal

## pnpm
pnpm exec pruvious mirror

## npm
npx pruvious mirror

The command will ask you to choose the mirror direction (up or down) and automatically perform the migration on the selected server and site.

Backups

To backup your production site, run the following command in your local project:

# Terminal

## pnpm
pnpm exec pruvious backup

## npm
npx pruvious backup

To restore a backup, run:

# Terminal

## pnpm
pnpm exec pruvious restore

## npm
npx pruvious restore

Manual deployment

If you prefer to manually deploy your website, take a look at the official Nuxt documentation since the process is the same.

Here is a reference to an nginx config that is used when deploying the website with the CLI tool.

# example.com.conf

map $sent_http_content_type $expires {
  "text/html" epoch;
  "text/html; charset=utf-8" epoch;
  default off;
}

map $request_uri $cache_tag {
  ~/uploads/ "public, max-age=2592000";
  default "";
}

server {
  listen 80;
  server_name example.com www.example.com;
  rewrite ^(.*) https://example.com$1 permanent;
}

server {
  listen 443 ssl http2;
  server_name example.com www.example.com;
  client_max_body_size 16M;

  if ($host = "www.example.com") {
    return 301 https://example.com$request_uri;
  }

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

  location / {
    add_header Access-Control-Allow-Origin *;
    expires $expires;

    proxy_redirect off;
    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;
    proxy_read_timeout 1m;
    proxy_connect_timeout 1m;
    proxy_pass http://127.0.0.1:3000/;

    rewrite ^/(.*)/$ /$1 permanent;
  }

  location /uploads {
    alias /srv/example.com/.uploads;
  }

  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

If you prefer to use pm2 as the process manager on your server, here's an example of an ecosystem file:

# ecosystem.config.js

module.exports = {
  apps: [
    {
      name: 'example.com',
      port: 3000,
      exec_mode: 'cluster',
      instances: 'max',
      autorestart: true,
      script: '/srv/example.com/.output/server/index.mjs',
      cwd: '/srv/example.com',
      env: {
        NODE_ENV: 'production',
        NUXT_PRUVIOUS_JWT_SECRET_KEY: 'random-secret-key', // https://pruvious.com/generate-key
      },
    },
  ],
}

Continue your learning journey by Digging deeper.

Last updated on March 16, 2024 at 13:20