Nginx Installation and Key Commands for Mastery
Nginx is a high-performance open source web server. It is a very popular software designed to process HTTP requests from clients (e.g. web browsers) and provide them with web pages and other content. Installing Nginx is very simple and is based on just one command. Enter the following command to easily install this web server:
apt install nginx
You must agree to the installation by pressing Y. The result will be something like this.
This article uses Debian 12 and all commands are run as root. You always get this access when you buy virtual or dedicated servers from AlexHost.
Run Nginx
Starting Nginx is quite simple. Just run the following command:
systemctl start nginx
If successful, the command does not produce any results.
If you are using a Linux distribution without systemd to run Nginx, enter:
service start nginx
Instead of starting the Nginx service manually, it is recommended to configure it to start at system boot:
systemctl enable nginx
Restart Nginx
The restart process is quick, easy to learn, but very important. Whenever you make any changes to Nginx, you need to restart Nginx every time. The restart option will load the new configuration, start new workflows with the new configuration, and gracefully close the old workflows.
To restart Nginx, use one of the following commands:
systemctl reload nginx
service reload nginx
Testing the Nginx configuration
Whenever you make changes to the Nginx server configuration file, it is recommended that you test the configuration before restarting or rebooting the service.
Use the following command to check your Nginx configuration for syntax or system errors:
sudo nginx -t
The result will look something like this.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: the configuration file /etc/nginx/nginx.conf test is successful