NGINX is one of the most popular web server suites deployed across the internet. It’s efficient, versatile, and works well on pretty much any Linux distribution. Whether you need a local server for testing, or want to host a website for the masses, NGINX is easy to set up. It can also be used as a reverse proxy server.
In this guide, we’ll be going through the step by step instructions to install NGINX on a variety of Linux distributions. We’ll also go over some basic usage commands, like how to start and stop the service. Keep reading to get NGINX setup on your own Linux system.
In this tutorial you will learn:
- How to install NGINX on various Linux distros
- How to manage the NGINX service
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | NGINX |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Install NGINX
NGINX is available in the official repositories of all Linux distributions. You can use the following commands to install NGINX on whichever distribution you’re running, by using the system’s package manager. After NGINX is installed, we’ll show you some basic commands that can help you manage the process.
Install NGINX on Debian, Ubuntu, and Linux Mint
Open a terminal and use the following commands to install NGINX on Debian, Ubuntu, Linux Mint, Kali, and other Debian or Ubuntu derivatives.
$ sudo apt update $ sudo apt install nginx
Install NGINX on Fedora, CentOS, and Red Hat
Open a terminal and use the following commands to install NGINX on Fedora, CentOS, Red Hat, and other Fedora or Red Hat derivatives.
$ sudo dnf upgrade $ sudo dnf install nginx
Install NGINX on Arch Linux and Manjaro
Open a terminal and use the following commands to install NGINX on Arch Linux, Manjaro, and other Arch derivatives.
$ sudo pacman -Syu $ sudo pacman -S nginx
Manage NGINX
Most Linux distributions, including all from the previous section, will use systemd to manage the NGINX service. Use the following commands to manage it on your system.
Check the status of NGINX (i.e. see if it’s running):
$ systemctl status nginx
Start or stop NGINX:
$ sudo systemctl start nginx AND $ sudo systemctl stop nginx
Enable or disable NGINX from starting automatically upon system boot:
$ sudo systemctl enable nginx AND $ sudo systemctl disable nginx
Reload or restart NGINX – reload will just reload configuration files, whereas restart will restart the service entirely:
$ sudo systemctl reload nginx AND $ sudo systemctl restart nginx
Check the NGINX configuration files for errors – especially helpful before committing changes in a production environment:
$ sudo nginx -t
Closing Thoughts
In this tutorial, we saw how to install NGINX on a variety of popular Linux distributions. We also learned how to manage the service with systemd, and check the configuration files for syntax errors. These instructions should be enough to get the software up and running. You can continue with our other guides to setup NGINX as a web server or reverse proxy server.