The Raspberry PI is great little mini computer the size of credit card. Despite it’s size it is extremely versatile and for developers it can be an extremely useful tool.
In this tutorial we will investigate how we can use the Raspberry Pi to become a lightweight web server, by installing Nginx on it.
What is Nginx?
NGINX (pronounced engine x) is a popular lightweight web server application you can install on the Raspberry Pi to allow it to serve web pages.
Why Install NgInx on Raspberry Pi
I’ve mentioned previously that developers could make great use of a raspberry pi, because at it’s core the Raspberry Pi is nothing more than a Linux based computer. Therefore Linux is an operating system that is extremely useful and every developer should have at least a rudimentary understanding of Linux.
One use case I particularly have found quite useful for the Raspberry while working from my home-based office, is to make use of them as lightweight web servers to enable the test of web applications.
I have also developed a lightweight DevOps environments to enable testing of Continuous Integration / Continuous Development (CI/CD).
Equipment used in this tutorial
- Raspberry Pi 3 Model B+
- RJ45 connection cable
- Broadband Router
- Network switch
- TP-LINK AV2000 Powerline Adapter Kit, 2-Port,
Refresh available packages
It is standard practice when working with Linux servers and installing new software to update your software repositories to ensure you get the latest or most update version of the software you want to install.
We can do this by running the following command:
We can install the NGINX web server application using the following command
Once the installation has completed we can start the Nginx service
We can now test that every is working as expected and fire up a web browser on the computer on your network and browse to the IP address of your Raspberry Pi .ie
You should see the default nginx test page.
By default, NGINX creates a test HTML file in the web folder. This default web page is served when you browse to
http://localhost/ on the Pi itself, or
http://192.168.1.7 (whatever the Pi’s IP address is) from another computer on the network.
To find the Pi’s IP address, type
hostname -I at the command line (or read more about finding your IP address).
You should be able to browse to the default web page either on the Pi or from another computer on the network and you should see the following:
This will confirm that Nginx is now installed on your raspberry pi. You can now easily edit the default page to provide an example of how you can use Nginx to host static web pages.
Change the default nginx default web page
NGINX defaults its web page location to
/var/www/html on Raspbian.
We can use nano to create a simple web page, to test this.
We can now add this simple HTML to create a very simple web page
simply save and close this file by using
We can now browse to the website on the Raspberry Pi and instantly see our changes.
This is made simple because the default configuration in the Nginx enabled sites enables any file named as index.html to be the default page. The nginx test page we seen earlier is actually named
if we list the files in
/var/www/html we will now see we have two files
You can add and edit any more files as you choose as required.
We have now successfully configured our Raspberry Pi to be able to serve static web pages. Which can be great fun to develop small house hold web sites etc.