Setting up NGINX web server in Raspberry Pi

Learn to create and using NGINX web server in Raspberry Pi. 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. Like Apache, NGINX can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP. So, let’s start.

Step 1: Installing NGINX in Raspberry Pi

Start Terminal window in Raspberry Pi and install NGINX by entering below given command.

sudo apt-get install nginx

To start NGINX web server enter the following command.

sudo /etc/init.d/nginx start

Step 2: Testing NGINX web server.

By default, NGINX has test HTML file in the web folder. This page will be served at localhost on Raspberry Pi and will be accessed through following ways.

  1. http://localhost/
  2. http://"ip address of your Raspberry Pi"/

Step 3: Build Advanced Webpage

Follow below-given steps to build NGINX web server in Raspberry Pi.

  1. Change default page located at “/var/www/html/index.html”
  2. To edit this file, you need to change ownership to your username. Assuming your username is Pi, use following code to change ownership.
    sudo chown pi: index.html
  3. Change contents of “index.html” to your preferred HTML content and save the file. For testing purpose, you can use HTML contents form this page. HTML content is in step 3 of the page.
  4. For using PHP, you must save the file as “index.php”
  5. To see changes take place, go to the browser and reload the page.

Using NGINX server you can view your web pages on another computer connected to the same network.

For basic hardware information about Raspberry PI 3, Click here

Leave a Reply