Install and Configure NGINX Server on Raspberry Pi
Jun 26, 2023
Quick and easy installation and configuration of NGINX Server on Raspberry Pi for serving static websites.
Jul 1, 2023 06:12 PM
According to the NGINX website:
NGINX is open-source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.
In this post, we will be using this sophisticated software as a web server for serving our static website on Raspberry Pi. You also can configure it to serve any web application with a server or multiple websites and applications.
First things first, you need to update your apt repository after the Raspberry Pi installation. You can find a guide for installation in this post
sudo apt update
It is extremely easy to install NGINX with the apt repository. Just run the command below and it will be ready!
sudo apt install nginx
After that, you can use the command below to start the NGINX server.
sudo /etc/init.d/nginx start
Now you can go to the browser and write your Raspberry Pi’s IP address to the address bar. You should see the default NGINX page below.
You also can use the
systemctlcommand to check if the NGINX service is still running from the terminal.
sudo systemctl status nginx
You should copy your static website to Raspberry Pi’s local file system. I just created one in the “/home/pi/mysite/index.html” as an example. Below you can see the contents of the index file.
Open up the
/etc/nginx/sites-available/defaultfile in nano with root privileges with the command below.
sudo nano /etc/nginx/sites-available/default
Scroll down to the line that starts with the
Change the line to point to your website’s root directory.
You can save the file and exit the nano editor by pressing
To restart the NGINX Server you can use the command below.
sudo systemctl restart nginx
Go to your browser and refresh the page that you opened with the IP address of your Raspberry Pi. You should be able to see your website.
In this post we used NGINX to serve this horrendous placeholder website, I am sure you will use it for creative and beautiful projects. Have fun with your new web server!