0
0
Iot-protocolsHow-ToBeginner · 4 min read

How to Install Nginx on Raspberry Pi Quickly and Easily

To install nginx on a Raspberry Pi, first update your package list with sudo apt update. Then install nginx using sudo apt install nginx. Finally, start the nginx service with sudo systemctl start nginx and verify it is running.
📐

Syntax

These are the main commands to install and manage nginx on Raspberry Pi:

  • sudo apt update: Refreshes the list of available packages.
  • sudo apt install nginx: Installs the nginx web server.
  • sudo systemctl start nginx: Starts the nginx service.
  • sudo systemctl enable nginx: Makes nginx start automatically on boot.
  • sudo systemctl status nginx: Checks if nginx is running.
bash
sudo apt update
sudo apt install nginx
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
💻

Example

This example shows the full process to install nginx, start it, and check its status on Raspberry Pi.

bash
sudo apt update
sudo apt install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
Output
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2024-06-20 12:00:00 UTC; 10s ago Docs: man:nginx(8) Main PID: 1234 (nginx) Tasks: 3 (limit: 4915) Memory: 5.0M CGroup: /system.slice/nginx.service ├─1234 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ├─1235 nginx: worker process └─1236 nginx: worker process
⚠️

Common Pitfalls

Some common mistakes when installing nginx on Raspberry Pi include:

  • Not running sudo apt update first, which can cause installation errors.
  • Forgetting to start the nginx service after installation.
  • Not enabling nginx to start on boot, so it stops after reboot.
  • Trying to install without internet connection.

Always check the service status to confirm nginx is running.

bash
sudo apt install nginx
sudo systemctl status nginx

# Wrong: Not starting nginx
sudo systemctl start nginx

# Right: Start and enable nginx
sudo systemctl start nginx
sudo systemctl enable nginx
📊

Quick Reference

CommandPurpose
sudo apt updateRefresh package list
sudo apt install nginxInstall nginx web server
sudo systemctl start nginxStart nginx service
sudo systemctl enable nginxEnable nginx to start on boot
sudo systemctl status nginxCheck nginx service status

Key Takeaways

Always run sudo apt update before installing nginx to get the latest package info.
Use sudo apt install nginx to install the web server easily on Raspberry Pi.
Start nginx with sudo systemctl start nginx and enable it to run on boot with sudo systemctl enable nginx.
Check nginx status anytime with sudo systemctl status nginx to ensure it is running.
Make sure your Raspberry Pi is connected to the internet during installation.