How to install Nginx on Ubuntu 22.04, 24.04, and Linux-based systems. This will help you easily create websites and manage your web server. Nginx is an open-source proxy server that utilizes popular protocols such as HTTP, HTTPS, SMTP, POP3, and IMAP. Nginx comes with essential core features for a web server, making it lightweight compared to Apache.
Update system and install Nginx
Nginx is available in the Linux repositories so you can install it with APT. The first is to run the command below to update the packages in the system.
sudo apt update && sudo apt upgrade -y sudo apt install -y nginx -y
Of course, to keep the website/app up and running all the time, and if you use it on localhost, you don’t need to start it every time you open your computer, run the command to allow Nginx to start with the system.
sudo systemctl enable nginx
Nginx Directory Structure
When you successfully install Nginx on Ubuntu 22.04, Nginx configuration files are placed in the /etc/nginx
directory. However, other important directories related to Nginx may reside elsewhere in the system. Let’s explore each directory and its configuration.
1. /etc/nginx:
- nginx.conf: The main configuration file for Nginx. This file contains global settings for the web server, including http blocks, server blocks, and other directives.
- conf.d: Directory containing additional configuration files for Nginx. These files can be used to configure virtual server blocks, reverse proxy settings, and other features.
- snippets: Directory containing HTML or Nginx code snippets that can be reused in other configuration files.
- logs: This directory stores Nginx access and error log files. The default location is typically
/var/log/nginx/
. These log files are crucial for troubleshooting and debugging issues related to your application or website.
2. /var/www:
- html: Default directory containing HTML files and other web resources served by Nginx.
- sites-available: Directory containing available virtual server configuration files for Nginx.
- sites-enabled: Directory containing enabled virtual server configuration files that are currently being used by Nginx.
3. /usr/share/nginx:
- html: Directory containing default HTML files provided by Nginx.
- icons: Directory containing default icons used by Nginx.
- nginx: Directory containing Nginx binaries, libraries, and documentation.
Note:
- The Nginx directory structure and file system hierarchy may vary depending on your Linux distribution and installation method.
- Please refer to the official Nginx documentation for more detailed information on the directory structure and configuration files: https://docs.nginx.com/
Read more: