Installation and package management
- Prefer your distribution’s package manager (apt, yum/dnf, pacman, etc.) to install, upgrade, and remove NGINX. Package managers handle dependencies and updates, simplifying maintenance.
- Compile from source only when you need custom modules, patches, or are targeting an unsupported platform.
Use your OS package manager for most installations—it’s safer and easier to maintain than compiling NGINX from source.
Platforms and production recommendations
- Example commands in this course used Ubuntu; installation steps are similar across mainstream Linux distributions.
- You can test NGINX on Windows or macOS for learning, but run production NGINX on Linux where it is best supported and most commonly deployed.
Controlling NGINX processes
NGINX’s master process accepts signals via thenginx -s command for direct control. Common commands:
sudo systemctl restart nginx or sudo systemctl reload nginx. Use nginx -s when you need direct control of the NGINX master process.
Quick reference: common signals and systemd equivalents
Configuration structure
The main configuration file isnginx.conf. Key sections to understand:
- Global directives:
user,worker_processes,error_log, etc. eventsblock: connection-related settings (e.g.,worker_connections).httpblock: global HTTP settings, MIME types, gzip, proxy settings, etc.serverblocks: virtual hosts inside thehttpblock; eachserverhandles one or more hostnames/ports.
Use separate
server blocks to host multiple sites on a single NGINX instance.
Serving static files and virtual hosts
- NGINX is highly efficient at serving static content (HTML, CSS, JS, images).
- Host multiple sites by creating separate
serverblocks and settingserver_namefor each domain. - If
server_nameis omitted or does not match, NGINX uses the first matching server block for thatlistensocket. On distributions usingsites-enabled, the order of included files can determine which server becomes the default — this can cause unexpected site selection if not managed explicitly.
Customizing the default page
To replace the default NGINX welcome page, edit the document root (commonly/var/www/html/index.html) and add your own HTML (a simple “Hello World” page is a common first step). Ensure file permissions and ownership allow the NGINX worker processes to read the files.
Firewall and port management
- Enable and configure the host firewall (UFW, firewalld, nftables) on Linux servers. Only open the IPs and ports you expect to use.
- Ports 80 (HTTP) and 443 (HTTPS) are typically open for public websites. For internal testing, restrict access to known IPs.
- Cloud providers (AWS, GCP, Azure) have separate network-level firewalls/security groups—make sure these rules line up with your host firewall.
Do not forget to synchronize cloud provider security groups with your server’s firewall rules. A mismatch can leave your server unreachable or exposed.
