Back to lessons

Hosting Operations

Test Nginx Before Reload

You changed an Nginx config and need to validate syntax before reloading the service.

Command

nginx -t

What changed

Nothing changes. Nginx parses configuration and reports whether reload is safe.

Danger

safe

When to use it

Use this before any Nginx reload or deploy involving server blocks.

When not to use it

Do not treat a syntax pass as proof the upstream app or DNS is correct.

Undo or recovery

No state is changed.

Expected output

A syntax-ok message or a line number for the config error.

demo script

Disposable terminal steps

  1. nginx -t
  2. ls -l /etc/nginx/sites-enabled/
  3. grep -R "server_name" /etc/nginx/sites-enabled/

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
::exit-code::0
$ ls -l /etc/nginx/sites-enabled/
total 0
lrwxrwxrwx 1 root root 38 Jun 25 13:19 example.com -> /etc/nginx/sites-available/example.com
::exit-code::0
$ grep -R "server_name" /etc/nginx/sites-enabled/
/etc/nginx/sites-enabled/example.com:    server_name example.com www.example.com;
::exit-code::0

YouTube Short

Test Nginx before reload.

Before reloading Nginx, run the syntax check. It is faster than breaking a live site.

LinkedIn hook

The config looked fine. Nginx disagreed before reload broke anything.

Question: Do you run `nginx -t` before every reload?

experiments

A/B tests to run

Metric: linkedin_save_rate

A: Test Nginx before reload.

B: The config looked fine. Nginx disagreed.