DebianDebian Based

How To Install Nginx on Debian 12

Install Nginx on Debian 12

In this tutorial, we will show you how to install Nginx on Debian 12. For those of you who didn’t know, Nginx, a powerful and high-performance web server, can significantly enhance your website’s speed, scalability, and overall performance. By installing Nginx on Debian 12, you can harness its advanced features and leverage its efficiency.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Nginx web server on a Debian 12 (Bookworm).


  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Nginx.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Nginx on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt install apt-transport-https lsb-release ca-certificates

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing Nginx on Debian 12.

Now that your system is up to date, it’s time to install PHP on Debian 12 using the following command below:

sudo apt install nginx

During the installation, Nginx will be configured as a service that starts automatically when the system boots. Once the installation is complete, Nginx is ready to be set up and optimized.

Step 3. Basic Nginx Configuration.

Properly configuring Nginx is crucial for optimal performance. Follow these steps to ensure a smooth configuration process.

  • Starting Nginx.

To start Nginx, execute the following command:

sudo systemctl start nginx
  • Checking Nginx’s Status.

To verify if Nginx is running correctly, use the following command:

sudo systemctl status nginx

Step 4. Adjusting Firewall Rules.

To allow Nginx traffic through the firewall, you need to configure the appropriate rules. Follow these steps to adjust the firewall settings:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Make sure to enable the firewall after making the changes:

sudo ufw enable

Step 5. Testing Nginx Configuration.

After configuring Nginx, it’s essential to test the setup to ensure it functions properly. Follow these steps to create a Basic HTML Page:

nano index.html

Add the following file:

<!DOCTYPE html>
<title>Welcome to Idroot.US</title>
<h1>Hello, World!</h1>

Save the file and place it in the appropriate Nginx document root directory.

Step 6. Configuring Nginx Virtual Host.

Virtual hosts allow you to host multiple websites on a single server. Follow these steps to configure a basic virtual host in Nginx:

sudo nano /etc/nginx/conf.d/default.conf

Inside the file, add a new server block for your website. Customize the following example configuration based on your requirements:

server {
    listen 80;
    root /var/www/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;

Save the configuration file and exit the text editor, then verify the correctness of the Nginx configuration, and execute the following command:

sudo nginx -t

Remember to regularly update Nginx and review its configuration to ensure optimal performance. With Nginx powering your website, you can expect improved speed, scalability, and reliability, providing an excellent user experience for your visitors.

Congratulations! You have successfully installed Nginx. Thanks for using this tutorial for installing the latest version of the Nginx web server on Debian 11 Bookworm. For additional help or useful information, we recommend you check the official Nginx website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button