Activate an Nginx Web Server on a Pi (or any Linux)
ssh pi@raspberrypi
sudo apt update -y
sudo apt install nginx -y
-y
is a flag to accept the additional data sizes that come from the installation.
Optional Are you using an
ufw
firewall? Enable nginx with:sudo ufw allow 'Nginx Full'
In step 1, I used pi@raspberrypi
which means my hostname is raspberrypi
.
Let's get the IP (reference):
Option 1
HOST_IP1=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
echo $HOST_IP1
Option 2
HOST_IP=$(hostname -I | cut -f1 -d' ')
echo $HOST_IP
Now that we have nginx
installend & our host ip
, let's open our browser:
http://raspberrypi
or
http://192.168.86.24
Do you have the wrong IP Address? Does the page never load? List list other devices on your newtork with
namp
on mac, linux, or windows. Listing the devices might help you find the correct IP address.
cat /etc/nginx/sites-enabled/default
The actual source is linked from
/etc/nginx/sites-available
cat /var/www/html/*.html
The actual source is
/var/www/html/index.nginx-debian.html
sudo systemctl daemon-reload
sudo systemctl reload nginx
Using
reload
will not stop nginx. Usingstop
and thenstart
will. So willrestart
.
Now you're ready to learn more about nginx and using it for:
- Load Balancing
- Reverse Proxy
- API Gateway
And more.