



- Cost savings: fewer machines to run multiple sites.
- Centralized management: one NGINX instance handles routing and SSL termination.
- Better hardware utilization: run many low-traffic sites on the same host.
- Isolation by config: each site has its own server block file so you can change one site without touching others.
Notes about hostnames and IPs
server_nameaccepts domain names, wildcards (e.g.,*.example.com), and IP addresses. In practice you usually create DNS A/AAAA records pointing your hostname to the server IP.- Browsers assume port 80 for HTTP and 443 for HTTPS. Using non-standard ports (e.g.,
:8080) requires users to include the port in the URL and is less user-friendly.
proxy_pass directive inside a location block when proxying to backends.
Configuration organization and best practice
- You can put multiple server blocks in a single file, but it’s best to keep each virtual server in its own file (for example, within
/etc/nginx/sites-enabled/or/etc/nginx/conf.d/depending on your distribution). - Separating site configs keeps changes localized, simplifies automation, and reduces the risk of accidental changes to unrelated sites.
- Always test configuration changes before reloading NGINX.
Keep each site’s configuration in its own file (e.g.,
/etc/nginx/sites-enabled/honda.cars.com) so you can safely edit or remove one site without impacting the others.Before reloading NGINX after changes, run
nginx -t to test configuration syntax. If the test passes, reload with sudo systemctl reload nginx (or nginx -s reload). A failed nginx -t prevents a reload and keeps the running configuration intact.- NGINX official docs: https://nginx.org/en/docs/
- NGINX beginner guides and best practices: https://nginx.org/en/docs/beginners_guide.html
- Try creating two simple sites on a VM: add DNS or
/etc/hostsentries, create site files under/etc/nginx/sites-enabled/, runnginx -t, and reload NGINX. Test accessing both sites by hostname to see how NGINX chooses the correct server block.