Introduction
Before we discuss how to install NGINX mainline on Debian 12, let's first understand-What is Nginx Mainline?
Nginx Mainline is the development version of the popular web server, Nginx. It provides the latest features, bug fixes, and performance improvements. Utilizing Nginx's state-of-the-art features is possible when you install Nginx Mainline on Debian 12.
This tutorial will walk you through the process of installing Nginx Mainline on Debian 12.
Advantages
- Latest Features and Enhancements: Nginx Mainline offers the most recent updates, ensuring access to the latest features, performance optimizations, and security enhancements.
- Enhanced Performance: Nginx is known for its high-performance architecture and efficient resource utilization, allowing it to handle many concurrent connections and requests.
- Flexible Configuration Options: Nginx provides extensive configuration options, allowing fine-tuning and customization to meet specific requirements and optimize server performance.
- Ease of Use: Nginx is designed with ease-of-use in mind, providing clear documentation and a user-friendly configuration syntax that simplifies server setup and management.
- Support and Community: Nginx has a large and active community of users and developers, ensuring access to support, troubleshooting resources, and a wealth of community-contributed modules and extensions.
Nginx Mainline Pre-Installation Steps on Debian 12
Step 1: Update Debian System Packages
Making sure your Debian system is up-to-date is the first step. By doing this, you can be confident that all of your packages and security fixes are up-to-date. You must first run the following command in your terminal in order to update the packages themselves as well as the package list:
sudo apt update
To update any out-of-date packages, use the command below:
sudo apt upgrade -y
Step 2: Install Required Packages
The current Nginx mainline version can be installed on your Debian system using one of two methods, both of which could need extra packages. What's needed can be installed with the following command:
sudo apt install curl gnupg2 ca-certificates lsb-release dirmngr software-properties-common apt-transport-https -y
Most may be installed already, but re-run this command to ensure they are.
Install Nginx Mainline on Debian 12 via Nginx.org
By using the official APT repository of nginx.org, the most recent stable or mainline version of Nginx is obtained directly. If you want to be the first to know when a new version of Nginx is published, this is the best version.
Step 1: Import nginx.org
GPG Key on Debian
The Nginx GPG key needs to be downloaded and added first. To confirm the validity of the packages we'll install, we need this key:
curl -fSsL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg > /dev/null
The GPG key will now be used to confirm that the key was successfully imported:
gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
You should see the result verifying the details of the key, if the import was successful.
Example output:
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid nginx signing key <[email protected]>
Step 3: Import Nginx.org APT Repository on Debian
We may add the Nginx Mainline or Stable repository to our APT package manager list now that the GPG key is safely stored.
Use this method to import the Nginx Mainline repository:
echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
Or in the case of the Nginx Stable repository:
echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
Setting up APT pinning to favor Nginx packages from the nginx.org repository over any packages from the Debian default repository or other third-party repositories is our next goal.
This is accomplished using the following command:
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
Example output:
x\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
Package: *
Pin: origin nginx.org
Pin: release o=nginx
Pin-Priority: 900
We currently need to include the latest additions into our APT repository.
sudo apt update
Step 4: Install Nginx Mainline or Stable from Nginx.org on Debian
Now that everything is configured properly, we can install Nginx:
sudo apt install nginx
It's important to confirm the installation was successful after it's finished. We may verify the installed version of Nginx to ensure proper installation:
nginx -v
Depending on the version you installed, the most recent Nginx Mainline or Stable version should be shown in the command output.
Install Nginx Mainline on Debian 12 via PPA
The second approach makes advantage of the well-known PPA through Ondřej Surþ, who many in the Ubuntu and Debian community are aware of as the person who keeps upstream releases of the Apache, Nginx, and PHP repositories.
Although this version lacks the speed of the Nginx.org APT repository, it does have more compiled modules, one of which uses Brotli.
Step 1: Import Nginx PPA on Debian
It's simple to import the Nginx Mainline repository from the PPA by using the following command:
curl -sSL https://packages.sury.org/nginx-mainline/README.txt | sudo bash -x
If you would rather go back to the most recent stable version or utilize stable instead of mainline, you can import this version using the following command:
curl -sSL https://packages.sury.org/nginx/README.txt | sudo bash -x
To prevent conflicts, make sure you have deleted the mainline version.
Step 2: Install Nginx Mainline on Debian
Now, you can use the following command to install Nginx mainline or stable:
sudo apt install nginx
Step 3: Confirm Nginx Mainline Installation
Once Nginx is installed, run the following command to verify the installation:
nginx -v
The result ought to display the installed version of Nginx; if it corresponds with the most recent mainline version, the mainline installation was successful.
Additional Nginx Tips with Nginx PPA Installation
Setup Brotli on Nginx Mainline or Stable
Since the brotli
module is included in both Nginx mainline and stable versions, you can install it by running the following command:
sudo apt install libnginx-mod-brotli
Open the Nginx configuration file you have now:
sudo nano /etc/nginx/nginx.conf
You must add the following configuration to the HTTP block of your nginx.conf
configuration file in order to activate Brotli compression on your Nginx server:
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types application/atom+xml application/javascript application/json application/rss+xml
application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype
application/x-font-ttf application/x-javascript application/xhtml+xml application/xml
font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon
image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;
To make sure there are no issues, try the nginx settings now before reloading:
sudo nginx -t
Now use the following command to test brotli
compression:
curl -I --compressed http://your-server.com/some-path
In the output, look for a header that states Content-Encoding: br
. This suggests the application of Brotli compression:
Content-Encoding: br
FAQs to Install Nginx Mainline on Debian 12
How can I add the Nginx Mainline repository on Debian 12?
To add the Nginx Mainline repository, you need to create a file in /etc/apt/sources.list.d/
with the appropriate repository information and then update your package list using apt update
.
Can I install Nginx Mainline alongside the stable version on Debian 12?
Yes, you can install Nginx Mainline alongside the stable version. However, you need to ensure that they listen on different ports or IP addresses to prevent conflicts.
How do I uninstall the previously installed version of Nginx before installing Mainline on Debian 12?
You can uninstall the previously installed version using the package manager. For example, use apt remove nginx
to remove the stable version before installing Nginx Mainline.
Can I upgrade from the stable version to Nginx Mainline on Debian 12 without uninstalling?
Yes, you can perform an in-place upgrade by adding the Nginx Mainline repository and then upgrading the package using apt upgrade
.
How can I check the status of the Nginx Mainline service on Debian 12?
You can use the command systemctl status nginx
to check the status of the Nginx Mainline service. It will show whether it is running or encountering any errors.
How can I configure Nginx Mainline on Debian 12?
Nginx Mainline configuration files are typically located in /etc/nginx/
. You can modify the nginx.conf
file and create or modify additional configuration files in the conf.d/
or sites-available/
directories to customize the server behavior.
Can I use Certbot to manage SSL certificates for Nginx Mainline on Debian 12?
Yes, Certbot is compatible with Nginx Mainline. You can use Certbot to automatically obtain and manage SSL certificates for your Nginx Mainline server.
Conclusion
Upgrading web server solutions means installing Nginx mainline or stable from the nginx.org repository or PPA on a Debian Linux distribution. As we've seen, the procedure is simple but guarantees that your server has the most recent, secure, and dependable version of Nginx installed.
Please feel free to ask any queries you may have in the comments section.