-
Why use package managers instead of compiling NGINX from source
- Prefer your distribution’s package manager (apt, yum/dnf, pacman) for routine installs and upgrades. Compiling from source is only recommended when you need custom modules or non-standard builds (for example, third-party NGINX modules not available as packages).
- Keywords: NGINX installation, package manager, compile NGINX from source.
-
Installing NGINX across distributions
- Examples used Ubuntu, but the same concepts apply on other Linux distributions. For Ubuntu/Debian:
- For RHEL/CentOS/Fedora, use
yum/dnf; for Arch, usepacman. - Keywords: install NGINX Ubuntu, install NGINX Debian, install NGINX CentOS.
- Examples used Ubuntu, but the same concepts apply on other Linux distributions. For Ubuntu/Debian:
-
Platform guidance
- While you can test NGINX on Windows or macOS for learning, Linux is the recommended platform for production NGINX servers.
Avoid running production NGINX on Windows or macOS—Linux is the standard and most supported platform for production NGINX deployments.
-
Controlling the NGINX process
- Use your service manager for lifecycle operations:
- Send signals directly to the master process:
- Keywords: systemctl nginx, nginx -s reload, graceful reload NGINX.
- Use your service manager for lifecycle operations:
-
NGINX configuration structure
- The primary config file is
nginx.conf. Its main parts are the global directives, theeventsblock, thehttpblock, and insidehttpmultipleserverblocks for virtual hosting. - You can host multiple sites on one NGINX instance using separate
serverblocks. Always setserver_namefor each site; if noserver_namematches, NGINX uses the default server for that listen address (the first matching server block, or the one markeddefault_server).
- The primary config file is
Tip: Use
default_server on the listen directive to explicitly choose the server block that should handle unmatched requests.- Quick reference:
nginx.confblocks
-
Serving static files and reverse proxy usage
- NGINX excels at serving static assets (HTML, CSS, JS, images) and is often used as a reverse proxy in front of application servers (Node, Python, Ruby, etc.).
- Example minimal server block for a static site:
- Keywords: NGINX static files, NGINX reverse proxy, NGINX server block example.
-
Customizing the default page and adding a simple “Hello World”
- Replace the default root document (commonly
/var/www/html/index.html) with your own static HTML to change the default NGINX page. A basic file likeindex.htmlwith “Hello World” is enough for testing.
- Replace the default root document (commonly
-
Firewalls and port management
- Always run a host firewall (e.g.,
ufw,firewalld) and a cloud provider security policy. Only open the ports and IPs you intend to expose. - Common public ports:
- 80 — HTTP
- 443 — HTTPS
- For private testing, restrict access to specific IP addresses.
- Cloud provider firewall references:
- Always run a host firewall (e.g.,
