{"id":5312,"date":"2020-01-09T13:01:14","date_gmt":"2020-01-09T07:31:14","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=5312"},"modified":"2026-11-12T18:22:16","modified_gmt":"2026-11-12T12:52:16","slug":"keystone-js-deployment-on-ubuntu-16-04-18-04","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/keystone-js-deployment-on-ubuntu-16-04-18-04\/","title":{"rendered":"How to Deploy KeystoneJS on Ubuntu with Nginx and PM2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date:<\/strong> January 7, 2020<br><strong>Last Updated:<\/strong> November 10, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">KeystoneJS is an open-source Node.js framework for building database-driven applications and content management systems. It provides a configurable Admin UI, GraphQL API, authentication capabilities, and flexible data management.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Deploying a KeystoneJS application on an Ubuntu server requires configuring the Node.js runtime, installing application dependencies, setting up a database, and configuring a web server to handle incoming requests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we will explain <strong>how to deploy KeystoneJS on Ubuntu 24.04 LTS using Nginx and PM2<\/strong>. We will also cover domain configuration, application process management, and basic deployment verification.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before starting the deployment, make sure you have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Ubuntu 24.04 LTS server.<\/li>\n\n\n\n<li>Root or sudo access to the server.<\/li>\n\n\n\n<li>A domain name pointing to your server&#8217;s public IP address.<\/li>\n\n\n\n<li>A KeystoneJS 6 application or a new project.<\/li>\n\n\n\n<li>SSH access to the server.<\/li>\n\n\n\n<li>A database supported by your KeystoneJS configuration, such as PostgreSQL, MySQL, or SQLite.<\/li>\n\n\n\n<li>Basic knowledge of Linux commands and Node.js.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> This guide uses Node.js 24 LTS as the example runtime. Check your application&#8217;s dependencies and <code>package.json<\/code> before selecting a Node.js version. Node.js 26 is also available as an Active LTS release.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Install and Configure Nginx<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx will act as a reverse proxy, forwarding incoming HTTP requests to the KeystoneJS application running on the local application port.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 Update Ubuntu packages<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Connect to your server through SSH and update the package repository.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt update\nsudo apt upgrade -y<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 Install Nginx<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Install the Nginx web server.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install nginx -y<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the Nginx service status.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl status nginx<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the service is not running, start and enable it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl start nginx\nsudo systemctl enable nginx<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1.3 Verify Nginx installation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open your browser and access:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">http:\/\/SERVER_IP_ADDRESS<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see the default Nginx welcome page.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.4 Configure your domain directory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a directory for your domain.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo mkdir -p \/var\/www\/domainname.com\/html<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Assign ownership to your deployment user.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo chown -R $USER:$USER \/var\/www\/domainname.com\/html<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set the appropriate directory permissions.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo chmod -R 755 \/var\/www\/domainname.com<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a sample HTML page to verify the domain configuration.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nano \/var\/www\/domainname.com\/html\/index.html<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following content:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;html>\n&lt;head>\n    &lt;title>KeystoneJS Deployment&lt;\/title>\n&lt;\/head>\n&lt;body>\n    &lt;h1>Nginx is configured successfully!&lt;\/h1>\n&lt;\/body>\n&lt;\/html><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save and close the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.5 Configure the Nginx server block<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a configuration file for your domain.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nano \/etc\/nginx\/sites-available\/domainname.com<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">server {\n    listen 80;\n    listen [::]:80;\n\n    server_name domainname.com www.domainname.com;\n\n    root \/var\/www\/domainname.com\/html;\n    index index.html;\n\n    location \/ {\n        try_files $uri $uri\/ =404;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable the configuration by creating a symbolic link.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo ln -s \/etc\/nginx\/sites-available\/domainname.com \/etc\/nginx\/sites-enabled\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Test the Nginx configuration.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nginx -t<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the configuration test succeeds, reload Nginx.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl reload nginx<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your domain should now display the sample HTML page.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Node.js and npm<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">KeystoneJS runs on Node.js. We will install Node.js 24 using the NodeSource repository.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, install the required packages.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install curl ca-certificates -y<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the Node.js 24 repository.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -fsSL https:\/\/deb.nodesource.com\/setup_24.x | sudo -E bash -<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Install Node.js.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install nodejs -y<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify the installed versions.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">node -v\nnpm -v<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure the installed Node.js version is compatible with your KeystoneJS application&#8217;s dependencies.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Create or Prepare the KeystoneJS Application<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can either create a new KeystoneJS application or deploy an existing project.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Option 1: Create a new KeystoneJS project<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For a new project, run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm create keystone-app@latest<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the prompts to create your application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to the project directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd my-app<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Install the dependencies.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Start the application in development mode for initial testing.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm run dev<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By default, the development server runs at:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">http:\/\/localhost:3000<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Option 2: Deploy an existing KeystoneJS application<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you already have a KeystoneJS project hosted in a Git repository, install Git.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install git -y<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Clone your project.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git clone YOUR_GIT_REPOSITORY_URL<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to the application directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd YOUR_PROJECT_DIRECTORY<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Install the application dependencies.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm ci<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>npm ci<\/code> when your repository contains a valid <code>package-lock.json<\/code>. Otherwise, follow the package manager and installation instructions specified by your project.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Configure the Database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">KeystoneJS 6 uses Prisma for database access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It supports the following database providers:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PostgreSQL<\/li>\n\n\n\n<li>MySQL<\/li>\n\n\n\n<li>SQLite<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The database provider is configured in the KeystoneJS project configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For production deployments, use an appropriately secured database and configure its connection details through environment variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, an environment file may contain:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DATABASE_URL=\"YOUR_DATABASE_CONNECTION_STRING\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The actual variable name and connection format must match your application&#8217;s Prisma and KeystoneJS configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create or update the environment file in your project directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nano .env<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the required application environment variables and database connection details.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Restrict access to the environment file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">chmod 600 .env<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Do not commit <code>.env<\/code> files, database credentials, or other application secrets to your Git repository.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding, confirm that the database is reachable from the application server and that the application is configured for the correct database provider.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Build the KeystoneJS Application<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before starting KeystoneJS in production mode, generate the production build.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to the application directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd YOUR_PROJECT_DIRECTORY<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run the production build.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npx keystone build<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If your project uses Prisma migrations, deploy the committed production migrations.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npx prisma migrate deploy<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run database migrations against the intended production database only. Do not run production migrations from staging or preview deployments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For production deployments, KeystoneJS recommends building the application and starting it using its production commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Install and Configure PM2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PM2 is a process manager for Node.js applications. It helps keep the application running in the background and allows administrators to monitor and manage application processes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install PM2 globally.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo npm install -g pm2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to your KeystoneJS project directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd YOUR_PROJECT_DIRECTORY<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Start the application using PM2.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 start npm --name keystone -- start<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the application status.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 status<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">View application logs.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 logs keystone<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To monitor the application:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 monit<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure PM2 to start automatically<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Save the current PM2 process list.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 save<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Generate the startup command.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 startup<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">PM2 will display a command that needs to be executed with elevated privileges. Copy and execute the command shown in your terminal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This configures PM2 to restore the saved application processes after a server restart.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7: Configure Nginx as a Reverse Proxy<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that KeystoneJS is running on the local application port, configure Nginx to forward requests to it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the Nginx configuration file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nano \/etc\/nginx\/sites-available\/domainname.com<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace the earlier sample HTML configuration with the following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">server {\n    listen 80;\n    listen [::]:80;\n\n    server_name domainname.com www.domainname.com;\n\n    location \/ {\n        proxy_pass http:\/\/127.0.0.1:3000;\n\n        proxy_http_version 1.1;\n\n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto $scheme;\n\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection \"upgrade\";\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save the configuration and test it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nginx -t<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the syntax is valid, reload Nginx.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl reload nginx<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx will now forward incoming requests to the KeystoneJS application running on port 3000.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 8: Configure Firewall Rules<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If UFW is enabled, allow the required web traffic.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo ufw allow OpenSSH\nsudo ufw allow 'Nginx Full'<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the firewall status.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo ufw status<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For production, expose only the required public services. Keep the KeystoneJS application port restricted to localhost or the private network rather than opening port 3000 publicly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 9: Verify the KeystoneJS Deployment<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Open your browser and access your domain:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">http:\/\/domainname.com<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your KeystoneJS application should respond through Nginx.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also test the application locally from the server.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -I http:\/\/127.0.0.1:3000<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the PM2 process status.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 status<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Review the application logs if the application does not respond.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 logs keystone<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For production environments, configure HTTPS using a valid SSL\/TLS certificate and redirect HTTP traffic to HTTPS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting Common KeystoneJS Deployment Issues<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. KeystoneJS application is not starting<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check the PM2 logs.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 logs keystone<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify that dependencies are installed and the required environment variables are available.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Nginx returns a 502 Bad Gateway error<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A 502 error commonly occurs when Nginx cannot communicate with the application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the application process.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 status<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify that KeystoneJS is listening on the expected port.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo ss -lntp | grep 3000<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm that the Nginx <code>proxy_pass<\/code> destination matches the application&#8217;s actual listening address and port.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Database connection errors<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Verify the database connection string, database availability, network access, and database credentials.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check that Prisma migrations have been applied successfully.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Application does not start after a server reboot<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check whether PM2 has been configured for startup.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pm2 startup\npm2 save<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Also verify the PM2 systemd service and its associated user configuration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Deploying KeystoneJS on Ubuntu involves configuring the Node.js runtime, preparing the application and database, building the production application, and managing its process through PM2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By configuring Nginx as a reverse proxy, you can serve your KeystoneJS application through a domain name without exposing the application port directly to the public internet.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Following these steps provides a foundation for running a KeystoneJS application in a production environment. Remember to maintain supported software versions, secure application credentials, configure HTTPS, and monitor application and database health.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is KeystoneJS?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">KeystoneJS is an open-source Node.js framework used to build database-driven applications, content management systems, and GraphQL APIs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Can I deploy KeystoneJS on Ubuntu 24.04?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. You can deploy KeystoneJS on Ubuntu 24.04 by installing a compatible Node.js runtime, configuring a supported database, and setting up a production web server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Why is PM2 used with KeystoneJS?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PM2 manages Node.js application processes. It provides process monitoring, log management, background execution, and automatic restart capabilities.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Why use Nginx with KeystoneJS?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx acts as a reverse proxy, forwarding incoming HTTP or HTTPS requests to the KeystoneJS application. It also helps manage domain routing and SSL\/TLS configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Does KeystoneJS support MongoDB?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The current KeystoneJS 6 database configuration supports PostgreSQL, MySQL, and SQLite through Prisma. MongoDB is not a supported database provider in the standard KeystoneJS 6 configuration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/keystonejs.com\/docs\/\" target=\"_blank\" rel=\"noopener\">KeystoneJS Official Documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/keystonejs.com\/docs\/getting-started\/\" target=\"_blank\" rel=\"noopener\">KeystoneJS Getting Started Guide<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/keystonejs.com\/docs\/guides\/cli\/\" target=\"_blank\" rel=\"noopener\">KeystoneJS Production Deployment Guide<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/nodejs.org\/en\/about\/previous-releases\" target=\"_blank\" rel=\"noopener\">Node.js Official Release Schedule<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/\" target=\"_blank\" rel=\"noopener\">Nginx Official Documentation<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-install-nginx-and-lets-encrypt-ssl-with-html-docker-ubuntu-20-04\/\">How to Install Nginx and Let\u2019s Encrypt SSL with HTML + Docker \u2013 Ubuntu 20.04<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-setup-ssl-certificate-in-nginx-on-ubuntu-20-04\/\">How to setup SSL Certificate in Nginx on Ubuntu 20.04<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/connect-windows-agent-to-jenkins\/\">How to Connect a Windows Node (Agent) to Jenkins: A Complete Guide<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Need Assistance?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Need help deploying KeystoneJS, configuring Nginx, or managing Node.js applications on Ubuntu servers?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/pheonixsolutions.com\/devops-cloud\/\">Pheonix Solutions<\/a> technical team can assist with application deployment, server configuration, cloud infrastructure, and DevOps services.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For assistance, <a href=\"https:\/\/pheonixsolutions.com\/contact\/\" data-type=\"link\" data-id=\"https:\/\/pheonixsolutions.com\/contact\/\">contact us<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: January 7, 2020Last Updated: November 10, 2026 Introduction KeystoneJS is an open-source Node.js framework for building database-driven applications [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13253,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[741,740,522],"class_list":["post-5312","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-architecture","tag-deployment","tag-keystone-js","tag-ubuntu-18-0-4","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1nG","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/01\/Screenshot-2026-11-12-at-6.21.10-pm.png","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=5312"}],"version-history":[{"count":8,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5312\/revisions"}],"predecessor-version":[{"id":13255,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5312\/revisions\/13255"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media\/13253"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=5312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=5312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=5312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}