Installation guides

Installing Nginx on Debian

Step-by-Step Guide

  1. Update the Package Index
    Open a terminal and update the package index to ensure you have the latest information about available packages:
   sudo apt update
  1. Install Nginx
    Install Nginx using the apt package manager:
   sudo apt install nginx
  1. Adjust the Firewall
    Ensure that your firewall allows HTTP and HTTPS traffic. You can check the current UFW (Uncomplicated Firewall) status with:
   sudo ufw status

Allow the necessary traffic:

   sudo ufw allow 'Nginx Full'
  1. Verify Nginx Installation
    After the installation is complete, Nginx should start automatically. You can verify this by checking the service status:
   sudo systemctl status nginx

If Nginx is running, you should see an active (running) status.

  1. Test Nginx
    Open your web browser and visit your server’s IP address (http://your_server_ip/). You should see the Nginx default welcome page, indicating that the web server is running correctly.
  2. Configure Nginx (Optional)
    The main configuration file for Nginx is located at /etc/nginx/nginx.conf. You can edit this file to customize your Nginx configuration:
   sudo nano /etc/nginx/nginx.conf

After making changes, restart Nginx to apply them:

   sudo systemctl restart nginx
  1. Enable/Disable Modules
    Nginx uses modules to extend its functionality. You can enable or disable modules by editing the configuration files in the /etc/nginx/modules-enabled/ directory:
  • To enable a module, create a symbolic link in the modules-enabled directory:
    bash sudo ln -s /etc/nginx/modules-available/module_name.conf /etc/nginx/modules-enabled/
  • To disable a module, remove the symbolic link:
    bash sudo rm /etc/nginx/modules-enabled/module_name.conf
    After enabling or disabling modules, reload Nginx to apply changes:
   sudo systemctl reload nginx
  1. Set Up Server Blocks (Optional)
    Server blocks (similar to Apache’s virtual hosts) allow you to run multiple websites on a single server. To set up a server block, create a new configuration file in the /etc/nginx/sites-available/ directory:
   sudo nano /etc/nginx/sites-available/your_domain

Add the following basic configuration to the file:

   server {
       listen 80;
       server_name your_domain www.your_domain;

       root /var/www/your_domain;
       index index.html;

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

Save and close the file, then enable the new server block:

   sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
   sudo nginx -t
   sudo systemctl reload nginx
Other Recent Posts