Setup an NGINX Web Server using a Raspberry Pi

 

 
 

Introduction:-

    NGINX (pronounced as engine X) is a popular lightweight web server application which can serve HTML files over HTTP and with additional modules can serve dynamic web pages using scripting languages such as PHP.

     Now, we are just gonna be looking at how to install and setup NGINX Server on a Raspberry Pi and display a simple static webpage.

 

Installation:-

1.  Refresh database of available packages 

sudo apt update

2. Install NGINX Package

sudo apt install nginx

3. Start the Server

sudo /etc/init.d/nginx start


Setup:-

    By default NGINX puts a html file in the web folder. This default web is served when you browse to http://localhost/ on the Pi itself or http://192.168.1.1 (or Whatever your Pi address is) from another computer ensuring that both the computer and Pi is connected to the same network .Browse to the default web page either on the Pi or on from another computer on the network and you should see the following

NOTE:-

To find the IP Adress of your Pi , type in :

hostname -I

on the command line .

    Now we will make our own custom static page to display on our Web Server other than this default NGINX Page above. NGINX defaults its web page location to /var/www/html on Raspberry Pi OS. So navigate to this folder using cd command

cd /var/www/html

    Now there will be a file called index.nginx-debian.html in the html folder - This is the default NGINX html page displayed above. Since we're creating our own static page we can either this file or rename it as index.nginx-debian.html.bak .

    Create a new file called index.html on the same folder and edit that file with the html code given below :

<!DOCTYPE html>
<html>
<head>
<title>MircoKid</title>
<style>
    body  {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Hello from the MicroKid Team !!</h1>
<p>Here we can see that the html file we created is successfully displayed !!</p>
</body>
</html> 

(You can modify this code according to your liking)

Now reload the NGINX Server

sudo /etc/init.d/nginx reload

And refresh your Browser. Now you'll see your own custom html other than the deault NGINX html page.

Conclusion:-

   So there you have a fully functioning Web Server which can serve Static Webpages Straight from your Raspberry Pi .You can go in further and create a Dynamic Webpage using scripting languages, most preferably PHP, which I'll be discussing on my future Posts. So stay tuned for that...Peace !

Comments

Post a Comment

Popular Posts