How to Install Nginx on Kali Linux 2023.1

In this tutorial, we will explain how to install Nginx on Kali Linux 2023.1 system. Nginx, pronounced “engine x”, is a free, open-source, high-performance HTTP and reverse proxy server that powers some of the largest sites on the Internet.

Compared to Apache, Nginx can handle a large number of concurrent connections and has a smaller memory footprint per connection.

Requirements

Before starting the tutorial, make sure you are logged in as a user with sudo privileges and Apache or other services are not running on port 80 or 443.

Update Kali Linux

So first of all we have to update the Kali Linux. You can run the following command for that:

sudo apt update

 

Update Kali Linux 2023.1

Install Nginx on Kali Linux 2023.1

Nginx packages are available by default in Kali repositories. The installation is very simple, just run the following command:

sudo apt install nginx

Once the installation is completed, check the status of the Nginx service by typing:

sudo systemctl status nginx

The output should show you that the Nginx service is active and running:

──(kalilinuxize㉿kali)-[~] sudo systemctl status nginx       
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; disabled; preset: disabled)
     Active: active (running) since Thu 2023-02-02 16:10:13 PST; 13s ago
       Docs: man:nginx(8)
    Process: 6331 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exit>
    Process: 6332 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, statu>
   Main PID: 6333 (nginx)
      Tasks: 3 (limit: 7588)
     Memory: 9.5M
        CPU: 53ms
     CGroup: /system.slice/nginx.service
             ├─6333 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ├─6334 "nginx: worker process"
             └─6335 "nginx: worker process"
Feb 02 16:10:12 kali systemd[1]: Starting A high performance web server and a reverse proxy serv>
Feb 02 16:10:13 kali systemd[1]: Started A high performance web server and a reverse proxy serve>

To check the Nginx version type:

sudo nginx -v

 

Check nginx Version in Kali Linux

Adjust the Firewall

Assuming you are using UFW to manage your firewall, you’ll need to open HTTP (80) and HTTPS (443) ports.

You can do that by enabling the ‘Nginx Full’ profile which includes rules for both ports:

sudo ufw allow 'Nginx Full'

To verify the firewall status type:

sudo ufw status

Check Installation

To test whether Nginx is working properly, open http://YOUR_IP address in the browser of your choice, and the default Nginx home page will be displayed as shown below:

Welcome to nginx

Manage Nginx service with systemctl

You can manage the Nginx service just like any other system block.

To stop the Nginx service, run:

sudo systemctl stop nginx

To start the Nginx service, type:

sudo systemctl run nginx

Restart Nginx service:

sudo systemctl restart nginx

Reload the Nginx service after making some configuration changes:

sudo systemctl reload nginx

Disable Nginx service to start on boot:

sudo systemctl disable nginx

Re-enable the Nginx service to restart on boot:

sudo systemctl enable nginx

Structure  of Nginx configuration file

  • All Nginx configuration files are located in the /etc/nginx/ directory.
  • The main Nginx configuration file is /etc/nginx/nginx.conf.
  • To make it easier to set up Nginx, it is recommended to create a separate configuration file for each domain. You can have as many server block files as you want.
  • Nginx server block files are stored in /etc/nginx/sites-available directory. Configuration files located in this directory are not used by Nginx unless they are associated with the /etc/nginx/sites-enabled directory.
  • To enable Server Blocking, you need to create a symbolic link (pointer) from the configuration file sites in the Available Sites directory to the Enabled Sites directory.
  • It is recommended to follow a standard naming convention, for example, if your domain name is mydomain.com then your configuration file should be /etc/nginx/sites-available/mydomain.com.conf .
  • The /etc/nginx/snippets directory contains configuration snippets that can be included in server block files. If you use repetitive configuration segments, you can turn those segments into code snippets and include the code snippet file in the server block.
  • Nginx log files (access.log and error.log) are located in the /var/log/nginx/ directory. It is recommended to keep separate access and error logs for each server block.
  • You can set your domain document root to any location you choose. The most common locations for webroot include:
    • /home/<username>/<sitename>
    • /var/www/<sitename>
    • /var/www/html/<sitename>
    • /opt/<sitename>

Conclusion

Congratulations, you have successfully installed Nginx on your Kali Linux 2023.1 server. You are now ready to deploy your application and use Nginx as a web server or proxy.

If you have any questions, please leave them in the comments below.

Related Linux Tutorials:

Leave a Reply

Your email address will not be published. Required fields are marked *