About Nginx

Nginx is a highly powerful, most agile, and blazingly fast web server technology. It supports high traffic websites, and most of the big names in the online space run their web front-ends on Nginx. Nginx and security go hand in hand as well. In this short article we will see how to use Nginx web server on the Raspberry PI platform.

About Raspberry PI

Think of Raspberry PI as a teeny tiny computer (your pocket size just like mobile) which you can use to learn to program. It’s the first point of contact for any new maker. You can buy Raspberry PI from just under 32 Dollars from PiHUT or its relatives. It normally contains a broadband chip, 4 or more USB ports, stereo output, composite video port, full-size HDMI, CSI camera port, 32 or 64-bit CPU, 802.11 bgn wireless LAN, Bluetooth 4.x etc. This is a lot of stuff on such a small piece. If it contains this much then rest assured you can do a lot of on top of it. In this article, I will share how you can install Nginx on it.

Nginx on Raspberry PI

As said earlier Nginx can serve HTML pages, dynamic or static, on HTTP. It can do so through your Raspberry PI. So effectively your Raspberry PI is going to be a server. Either you get a server from Amazon Web Services, GoDaddy or it’s friends, or you can make one at home. Do the following to do the trick.

Now find the IP address of your PI, and use this IP address to construct a URL like this http://[Your-PI-IP] e.g. http://192.168.1.2. You can use this URL on any other computer over the network on which your PI is accessible to see Nginx output.

Running your own application on Nginx

Nginx stores the web pages which it serves in /var/www/html

Go to this folder and change the default file which is serving the page that you looked earlier on another computer.

Dynamic content on Nginx

Above example showed how you serve static HTML. If you want to serve dynamic HTML then you can install PHP on your RaspberryPI. Do the following to do the dew.

Once PHP is installed you need to enable it on Nginx. Go to the file /etc/nginx/sites-enabled/default and change the line

to

Go to the end of this file and add the following

Save the file and restart you Nginx server by doing the following

Now go the /var/www/html folder and make an index.php file. Do your PHP stuff there and then access it using the Raspberry’s IP address from a remote machine. You will see the results.

Conclusion

You can serve any web application using Nginx. You can also fine tune your Nginx installation.

Enjoy the fresh smell of your Rasberry with a new flavour on top.