Install Nginx on Raspberry Pi

Install Nginx on Raspberry Pi

Nginx is an open-source web server that delivers web content to clients. In addition to serving static and dynamic web content, it can function as a reverse proxy, load balancer, cache server, and much more, making it a popular choice for high-performance web applications.

This tutorial explains how to install Nginx on Raspberry Pi.

Install Nginx

Download GPG key:

sudo wget -qO /etc/apt/trusted.gpg.d/nginx-key.asc https://nginx.org/keys/nginx_signing.key

Add repository:

echo "deb [arch=arm64] http://nginx.org/packages/debian/ $(lsb_release -sc) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list

Run the following command to update the package lists:

sudo apt update

Install Nginx:

sudo apt install -y nginx

Add the nginx user to the www-data group to grant the Nginx process the necessary permissions to access and manage web-related files and directories.

sudo usermod -aG www-data nginx

Execute the following command to start Nginx:

sudo service nginx start

The Nginx version can be checked using the following command:

nginx -v

Use the following command to verify if the Nginx service is running:

sudo service nginx status

Additionally, the Nginx service can be stopped or restarted using the following commands:

sudo service nginx stop
sudo service nginx restart

Testing Nginx

Retrieve the IP address of your Raspberry Pi:

hostname -I

Open a web browser and enter the IP address. You should see the default Nginx welcome page displayed, as shown below:

Nginx default page on Raspberry Pi

Uninstall Nginx

To completely remove Nginx along with its related dependencies, run the following command:

sudo apt purge --autoremove -y nginx

Remove Nginx user:

sudo deluser nginx

Delete the GPG key and repository:

sudo rm -rf /etc/apt/trusted.gpg.d/nginx-key.asc
sudo rm -rf /etc/apt/sources.list.d/nginx.list

Leave a Comment

Cancel reply

Your email address will not be published.