Nginx is an open-source web server that serves web content to clients. It can also be used as a reverse proxy, load balancer, cache server, and more. This tutorial demonstrates how to install Nginx on Ubuntu 26.04.
Install Nginx
Add the APT repository and signing key:
sudo tee /etc/apt/sources.list.d/nginx.sources >/dev/null <<EOF
Types: deb
URIs: https://nginx.org/packages/mainline/ubuntu
Suites: $(lsb_release -sc)
Components: nginx
Signed-By:
$(curl -sS https://nginx.org/keys/nginx_signing.key | sed "s/^/ /")
EOF
To update the package lists, execute the following command:
sudo apt update
Install Nginx:
sudo apt install -y nginx
Add the nginx user to the www-data group. It will ensure that the Nginx process has appropriate permissions to access and manage web-related files and directories.
sudo usermod -aG www-data nginx
Run the following command to start Nginx:
sudo service nginx start
We can check Nginx version as follows:
nginx -v
We can check whether Nginx service is running with command:
sudo service nginx status
Also, we can stop or restart the Nginx service:
sudo service nginx stop
sudo service nginx restart
Testing Nginx
Get the IP address of your machine:
hostname -I
Open a web browser and type the IP address. The default Nginx welcome page will be presented as shown below:
Uninstall Nginx
If you decided to completely remove Nginx and related dependencies, execute the following command:
sudo apt purge --autoremove -y nginx
Remove Nginx user:
sudo deluser nginx
Remove the repository configuration file:
sudo rm -rf /etc/apt/sources.list.d/nginx.sources
Leave a Comment
Cancel reply