# Installing, Files and Controlling NGINX — Nginx

Source: https://www.skillbyai.com/en/nginx/f-install

> Install NGINX, find its files, test configuration and reload safely.

## Where things live and how to change them safely

Install from your distribution (`apt install nginx`, `dnf install nginx`) or, for newer versions, from the official **nginx.org repositories**; the official **Docker image** `nginx` is common in containers. Key locations on Debian and Ubuntu: main configuration `/etc/nginx/nginx.conf`; site configurations in `/etc/nginx/sites-available/` linked into `/etc/nginx/sites-enabled/` (distribution convention), or `/etc/nginx/conf.d/*.conf` (the convention in official packages); logs in `/var/log/nginx/`; default content in `/usr/share/nginx/html` or `/var/www/html`. Always **test** before applying: `nginx -t` checks syntax and file references, and `nginx -T` prints the whole merged configuration, very useful for debugging includes. Apply changes with a **graceful reload** (`nginx -s reload` or `systemctl reload nginx`): the master starts new workers with the new configuration while old workers finish their in-flight requests, so there is **no downtime**. A full restart drops connections and is rarely needed.

## Everyday control commands

Test, inspect and reload without dropping connections.

```bash
sudo nginx -t                    # syntax and file checks
sudo nginx -T | less             # full effective configuration, all includes expanded
sudo systemctl reload nginx      # graceful: new workers, old ones finish requests
sudo systemctl status nginx
nginx -v                         # version
nginx -V 2>&1 | tr ' ' '\n' | grep -- --with   # compiled-in modules

# Docker
docker run -d -p 8080:80 -v "$PWD/site:/usr/share/nginx/html:ro" nginx:stable
```

## Changing the menu without closing the restaurant

A graceful reload is like printing new menus: tables already eating finish with the old menu, and new guests get the new one. Nobody is asked to leave halfway through a meal.

**Quiz:** What does `nginx -s reload` do?

- [ ] Stops NGINX immediately and starts it again
- [ ] Only checks syntax
- [ ] Clears all logs
- [x] Starts workers with the new configuration while old workers finish in-flight requests

*Answer:* Starts workers with the new configuration while old workers finish in-flight requests. A reload is graceful, avoiding dropped connections.
