By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
Cloudbooklet Logo
  • Artificial Intelligence
  • Applications
  • Linux
Notification

Free AI Image Generator

Submit Tool
AI Tools
Cloudbooklet AICloudbooklet AI
Search
AI Tools
Submit Tool
  • Artificial Intelligence
  • Applications
  • Google Cloud
  • Compute Engine
  • Linux

Top Articles

Explore the latest updated articles about AI and technology!
Gemini Ai

Google Gemini AI Launch: The Game-Changing Technology Explained

Gemini Ai

How to Login and Use Google Gemini AI Right now in Bard

Discord Layout

How to Change Discord Layout Back -New update

Follow US
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
Cloudbooklet © 2023 All rights reserved.

Home » Google Cloud » Setup Node.js with Apache Proxy on Ubuntu 18.04 for Production

Google CloudCompute Engine

Setup Node.js with Apache Proxy on Ubuntu 18.04 for Production

Last updated: 2020/04/23 at 5:35 AM
By Cloudbooklet
Setup Node.js With Apache Proxy On Ubuntu 18.04 For Production
SHARE
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Setup Node.js with Apache Proxy on Ubuntu 18.04 for production. This guide shows you how to install Node.js and configure it with Apache for production. You will also install and configure free Let’s Encrypt SSL and secure your installation.

This setup is tested on Google Cloud Platform which is running Ubuntu 18.04. This guide will also helps you set this up on AWS, DigitalOcean, or any other cloud or VPS or Dedicated Linux based servers.

Table of Contents
PrerequisitesStep 1: Install Node.jsStep 2: Create a Node.js ApplicationStep 3: Install Process ManagerStep 4: Install ApacheStep 5: Enable Apache modulesStep 6: Configure Apache ProxyStep 7: Test the setupStep 8: Install SSL CertificateConclusion

Prerequisites

If you plan to use Google Cloud for example you can follow this or you just need SSH access to your server with sudo privileges.

  • A running Compute Engine, see the Setting up Compute Engine Instance with Ubuntu 18.04
  • Initial Ubuntu Server Set up..
  • Setup Cloud DNS, see the Setting up Google Cloud DNS for your domain.

Step 1: Install Node.js

You can install the latest LTS release of Node.js

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install -y nodejs

Once the installation is complete you can check the node.js version and npm version using the following commands

node -v
npm -v

Some packages requires compiling from source so you need to install the build-essential package.

sudo apt install build-essential

Step 2: Create a Node.js Application

Now you can create a demo Node.js app

cd ~/
sudo nano server.js

Insert the following code into the file

const http = require('http');
const hostname = 'localhost';
const port = 3000;

const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Welcome to Node.js!\n');
});

server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}/`);
});

Save the file and exit.

Step 3: Install Process Manager

sudo npm install pm2@latest -g

Now you can start your app using the process manager

pm2 start server.js

Now your Node.js application is running in the background

Step 4: Install Apache

sudo apt install apache2

Remove default Apache configuration.

sudo a2dissite 000-default

Step 5: Enable Apache modules

Now you need to enable Apache proxy module and rewrite modules.

sudo a2enmod proxy proxy_http rewrite headers expires

Step 6: Configure Apache Proxy

Once the above mentioned steps are done you can configure Apache to serve Node.js application.

Create a new virtual host configuration for Node.js.

sudo nano /etc/apache2/sites-available/domain.conf

Add the below configurations to the file.

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyVia Full

    <Proxy *>
        Require all granted
    </Proxy>

    ProxyPass / http://127.0.0.1:3000/
    ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>

Hit CTRL + X followed by Y and Enter to save and close the file.

Enable the newly created configuration.

sudo a2ensite domain.conf

Now you can restart Apache.

sudo service apache2 restart

Step 7: Test the setup

Now you can visit your domain name in browser, you should view the output of your server.js (Welcome to Node.js!).

Step 8: Install SSL Certificate

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install python-certbot-apache

Now you have installed Certbot for Apache which automates the installation of Let’sEncrypt certificate.

You just need to execute the following command to install your certificate.

sudo certbot --apache -m your-email -d domain.com -d www.domain.com

When prompted you can choose to redirect all HTTP requests to HTTPS.

Once done when you visit your site you will be redirected with HTTPS.

Prepare yourself for a role working as an Information Technology Professional with Linux operating system

Conclusion

Now you have learned to install Node.js, Apache and configure it to run on production.

TAGGED: Node.js, Ubuntu 18.04
Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Reddit Telegram Copy Link Print
Share
7 Reviews 7 Reviews
  • Avatar Of AzazAzaz says:

    Very helpful. Thank you!

    Reply

Comments navigation

Older Reviews 1 2

Leave a review Cancel reply

Your email address will not be published. Required fields are marked *

Please select a rating!

Popular

Castro App
Castro App not working: How to Fix Them
Artificial Intelligence
Q-Star Ai
How Q-Star AI Could Achieve AGI with OpenAI’s Help
Artificial Intelligence
Amazon Q Ai
How Amazon Q AI Assistant Can Boost Your AWS Productivity
Artificial Intelligence
Amazon Titan
How Amazon Titan Image Generator Can Revolutionize Generative AI
Artificial Intelligence
- Advertisement -

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Related Stories

Uncover the stories that related to the post!
How To Setup Openai Reverse Proxy
Artificial IntelligenceDeep Learning

How to Setup OpenAI Reverse Proxy A Step-by-Step Guide

How To Install Git On Ubuntu 20.04
Google CloudLinux

How to Install Git on Linux

Vector Image
Data ScienceGoogle Cloud

DataStax Enhances Astra DB on Google Cloud with Vector Search Capability

How To Setup Ssh Keys On Ubuntu
Google CloudAWS

How to Setup SSH Keys on Ubuntu 20.04

Cloudbooklet Logo
  • Categories:
  • Artificial Intelligence
  • Applications
  • Google Cloud

Quick Links

  • About
  • Contact
  • Disclaimer
  • Privacy Policy
Cloudbooklet © 2023 All rights reserved.
Welcome Back!

Sign in to your account

Lost your password?