Greenwebpage Community Blog Tutorials How to Install Nginx on Debian 12: 4 Easy Methods
Tutorials

How to Install Nginx on Debian 12: 4 Easy Methods

Install-Nginx-on-Debian-12

Don’t know how to install Nginx on Debian 12? You’re at the right blog!

Nginx is a powerful and efficient web server that serves websites to users. It handles multiple requests simultaneously and acts as a reverse proxy and load balancer. It is known for its speed and low resource usage, which makes it ideal for high-traffic sites and applications.

In this guide, we’ll check out four different methods to install Nginx on your Debian 12 system. Moreover, we’ll also discuss its configuration and uninstallation.

So let’s start the guide!

Method 1: Installing Nginx Using the Debian Repository

The simplest way to install Nginx is via the Debian repository.

To do so, first, update your Debian 12 repository to manage dependencies:

sudo apt update

Now, install Nginx on Debian 12 by using the following command:

sudo apt install nginx

You can easily check the Nginx version with:

sudo nginx -v

If you want to start Nginx on Debian 12, then use:

sudo systemctl start nginx

Now, enable Nginx through:

sudo systemctl enable nginx

Method 2: Installing Nginx from its Official Repository

This method involves adding Nginx’s official repository to your sources list to install the latest version. It ensures you get the most up-to-date version of Nginx with all the latest features and fixes.

Firstly, import the Nginx official signing key with:

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo tee /etc/apt/trusted.gpg.d/nginx_signing.asc

Then, add the Ngnix repository to the sources list:

echo "deb https://nginx.org/packages/debian/ $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list

Now, update the packages list:

sudo apt update

Check the Nginx version for verification using:

sudo nginx -v

Method 3: Building Nginx from Source

This method involves compiling Nginx from its source code to customize or use a specific version. Also, it provides full control over the Nginx features.

First, install some required dependencies:

sudo apt install build-essential libpcre3 libpcre3-dev libssl-dev zlib1g zlib1g-dev

Now, install the your desired version of Nginx:

wget http://nginx.org/download/nginx-[desired-verison].tar.gz

Then, extract the downloaded archive:

tar -xzvf nginx-[desired-verison].tar.gz

After that, move the Nginx source directory:

cd nginx-[desired-verison]

Next, configure the Nginx build-in options:

./configure

Compile all the Nginx source code with:

make

Now, you can start Nginx on Debian 12 easily with:

sudo /usr/local/nginx/sbin/nginx

Method 4: Installing Nginx Using Aptitude

Using Aptitude to install Nginx improves dependency management and provides a user-friendly interface for package management.

If you want to install Nginx using the aptitude package manager, then first install it by using:

sudo apt install aptitude

Now, install Nginx using aptitude:

sudo aptitude install nginx

Configuring Nginx on Debian 12

Before configuring Nginx, it is important to set up the firewall because it controls which traffic can access your server, and protects it from unauthorized access and potential security threats. So, first list down all the allowed traffic with:

sudo ufw status

When the installation is complete, the web server should be already running:

To check its status, run:

systemctl status nginx

To verify that Nginx is running as expected, you should check the Nginx landing page.

For this purpose, first, you need to find your server’s IP address. For that, use:

ip addr show enp0s3 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

After that, enter the obtained IP address in the search bar:

http://server-ip-address

If the Nginx landing page appears on your screen, it means Nginx has been successfully installed and is running on your server:

Uninstalling Nginx on Debian 12

Either you have installed Nginx using the Debian repository or built it from the source, you can easily uninstall using the following command:

sudo apt remove nginx -y

If you have installed Nginx using the aptitude package manager, then execute:

sudo aptitude remove nginx -y

Conclusion

Installing Nginx on Debian 12 is simple and offers flexibility through various methods. Whether you use the Debian repository, the official Nginx repo, build from source, or utilize Aptitude, each approach ensures you get a high-performance web server that’s ideal for handling traffic efficiently.

Also, remember to configure your firewall to keep your server secure and verify the installation by checking Nginx’s landing page. 

Frequently Asked Questions

Nginx is a high-performance web server and reverse proxy server known for its speed and efficiency.
Nginx can run on most modern hardware. A minimal installation of Debian 12 is sufficient, with at least 512 MB of RAM recommended.
Before installing Nginx, it's good practice to update your system. You can do this by running: sudo apt update && sudo apt upgrade
To install Nginx, run the following command: sudo apt install nginx
You can start the Nginx service with: sudo systemctl start nginx

Exit mobile version