Beginner Fundamentals
Installing and Running Nginx
Before configuring Nginx, you need it installed and running. This lesson covers installation and the everyday commands to control it.
Install
On Debian or Ubuntu:
sudo apt update
sudo apt install nginx
On RHEL, CentOS, or Fedora:
sudo dnf install nginx
Start and Manage the Service
Most Linux systems use systemd. Use systemctl to control Nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
enable makes Nginx start automatically on boot.
Test the Configuration
Always check your config before applying it. A typo can take the server down:
sudo nginx -t
If it prints “syntax is ok” and “test is successful”, you are safe to reload.
Reload Without Downtime
After editing config, reload to apply changes without dropping connections:
sudo systemctl reload nginx
sudo nginx -s reload
Both work. reload re-reads the config gracefully. Use nginx -s stop to stop the server. Get into the habit of running nginx -t before every reload.