How to Configure NGINX on Ubuntu to Run a NodeJS Web Server?
Published in
3 min readJul 8, 2023
In this tutorial, we will learn how to configure NGINX on Ubuntu to run a NodeJS web server. NGINX is a popular web server that is used to serve web content. It is fast, reliable, and secure. It can also be used as a reverse proxy server for HTTP, HTTPS, and other protocols.
You might require the above setup while trying to run a web server on an AWS EC2 instance.
Prerequisites
Before you start, you’ll need the following:
- A Ubuntu server with an SSH access
- NGINX installed
- Node.js installed. Refer to this guide if you want to use NVM for managing Node.JS version on your machine.
Step 1: Create a Node.js Application
First, create a sample Node.js application that will serve as the basis of your Node.js web server.
Create a new file called app.js
and add the following code:
const http = require('http');
const port = 3000;
const requestHandler = (request, response) => {
console.log(request.url);
response.end('Hello Node.js Server!');
}
const server = http.createServer(requestHandler);
server.listen(port, (err) => {
if (err) {
return console.log('something bad…