yum or dnf instead of apt. Links to official docs are included for further reading.
If you’re on Debian/Ubuntu use
apt (or apt-get for scripts). On CentOS/RHEL use yum or dnf. Package names and service management with systemctl are the same across most modern distributions.Overview
Steps covered:- Update package lists
- Install Nginx
- Start and verify the Nginx service
- Confirm Nginx responds locally
- Review Nginx configuration files
- Check Nginx logs
1) Update package lists
Update the local package index so you install the latest package metadata. Note:apt update only refreshes metadata — it does not accept -y. Use -y with commands that change the system like apt install or apt upgrade.
2) Install Nginx
Install Nginx usingapt install. The sample below runs interactively (no -y) so you can see the prompt; add -y to accept automatically in scripts.
3) Start and verify the Nginx service
Check the service status withsystemctl. If the service is inactive, start it and verify it becomes active.
Active: active (running) line to confirm the service is up.
Before reloading Nginx after any configuration change, validate the config syntax to avoid downtime:
sudo nginx -t. If the test passes, apply changes with sudo systemctl reload nginx.4) Confirm Nginx is responding
Make a local HTTP request withcurl to verify the default site:
localhost.
5) Review Nginx configuration files
On Debian/Ubuntu, Nginx configuration lives under/etc/nginx. A typical directory listing looks like this:
/etc/nginx/nginx.conf:
- The
httpblock contains global HTTP settings, logging, gzip, etc. access_loganderror_logdefine where logs are written (default:/var/log/nginx/).- Include lines load additional files:
include /etc/nginx/conf.d/*.conf;loads.conffiles fromconf.d.include /etc/nginx/sites-enabled/*;loads enabled site definitions.
- Best practice: place site
server { ... }blocks insites-available/and symlink enabled ones intosites-enabled/.
The example
ssl_protocols line lists TLSv1 and TLSv1.1. For production, enable only modern protocols (for example: ssl_protocols TLSv1.2 TLSv1.3;) and follow current TLS hardening guides. Older protocols are insecure.6) Check logs
Nginx logs live in/var/log/nginx. Immediately after install they may be minimal:
access.log and error.log will populate. You can configure per-site log paths within each server block.
That’s it for this lesson. To practice, create two sample virtual hosts under
sites-available/, enable them by symlinking into sites-enabled/, and test access and logging.