A Practical Guide for Engineers
This article provides a complete walkthrough of turning a Raspberry Pi into a lightweight, reliable web server using the Nginx platform. The steps include installation, firewall configuration, service management, and verification procedures suitable for engineering development environments.
1. Installing Nginx on Raspberry Pi
After powering on the Raspberry Pi and entering the terminal interface, first update the local package index—especially if it has been a long time since the last update:
Once the package list is refreshed, you may upgrade existing software packages:
If you do not need to perform upgrades and simply want to install Nginx, run:
After installation completes, verify the installed version with:
A typical output might look like:
If the version number appears, Nginx has been successfully installed.
Next, connect your PC to the Raspberry Pi via Ethernet. Ensure both devices are configured within the same subnet. Open a browser and enter the Raspberry Pi’s IP address (e.g., 192.168.0.81). You should see the Nginx welcome page.
2. Configuring the UFW Firewall
If your system uses UFW (Uncomplicated Firewall), begin by listing all available application profiles:
Typical output on Ubuntu might include:
Profile Descriptions
-
Nginx Full: Opens both 80 (HTTP) and 443 (HTTPS)
-
Nginx HTTP: Opens only port 80
-
Nginx HTTPS: Opens only port 443
-
OpenSSH: Enables SSH service access
Enabling Profiles
To allow full access for both HTTP and HTTPS:
To allow only HTTPS:
To remove a rule:
Verify current firewall rules:
[Illustration Placeholder – UFW Status Output]
For advanced UFW operations, refer to:
Configuration Guide for UFW Firewall in Ubuntu Linux Development.
3. Managing the Nginx Service
Starting and Stopping the Service
Stop the Nginx service:
Start Nginx:
Restart the service:
Reloading Configuration Seamlessly
When you modify only configuration files, Nginx supports live reload without interrupting existing connections:
4. Enabling or Disabling Nginx at Startup
Nginx typically starts automatically at system boot.
To disable autostart:
To re-enable autostart:
5. Checking Nginx Service Status
To verify whether Nginx is running correctly:
If the output contains Active (running), the service is functioning properly.
6. Conclusion
With Nginx installed, firewall rules configured, and service management understood, your Raspberry Pi is now fully operational as a compact and efficient web server. This setup is ideal for prototyping, small-scale automation dashboards, IIoT gateways, and educational engineering projects.