Skip to content

/commands/nginx/nginx-t-test-configuration

nginx -t: test the configuration before reloading

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · nginx version: nginx/1.30.6updated 2026-10-20
tool
nginx
versions
nginx 1.x
os
any

nginx -t parses the configuration, opens the files it references (certificates, included files) and resolves upstream hostnames, then exits: 0 if the configuration is valid, 1 if not. It does not touch the running server, so the safe way to apply changes is nginx -t && nginx -s reload (or sudo nginx -t && sudo systemctl reload nginx).

A valid and a broken configuration

bash
mkdir -p logs temp
cat > nginx.conf <<'EOF'
pid logs/nginx.pid;
events {}
http {
  server {
    listen 127.0.0.1:8080;
    location / {
      return 200 "ok\n";
    }
  }
}
EOF
log() { sed -E 's/^[0-9/]+ [0-9:]+ \[([a-z]+)\] [0-9#]+: /[\1] /'; }
nginx -p . -c nginx.conf -e stderr -t 2>&1 | log; echo "exit status: ${PIPESTATUS[0]}"
sed -i 's/return 200/retrun 200/' nginx.conf
nginx -p . -c nginx.conf -e stderr -t 2>&1 | log; echo "exit status: ${PIPESTATUS[0]}"

Output

nginx: the configuration file ./nginx.conf syntax is ok
nginx: configuration file ./nginx.conf test is successful
exit status: 0
[emerg] unknown directive "retrun" in ./nginx.conf:7
nginx: configuration file ./nginx.conf test failed
exit status: 1

On a packaged install you just run sudo nginx -t; -p (prefix), -c (config file) and -e (error log) are only needed here because the example runs from a scratch directory.

Show the effective configuration

nginx -T tests the configuration and then prints it, with every include expanded and each file preceded by # configuration file …:. Use it to find which file sets a directive:

bash
sudo nginx -T 2>/dev/null | grep -n "client_max_body_size"

Command-line switches

SwitchDoes
-ttest the configuration and exit
-Ttest, then dump the full configuration
-qwith -t, print only errors
-s reload | reopen | stop | quitsignal the running master process
-c fileuse another configuration file
-p prefixset the prefix path (relative paths are resolved from it)
-e file | stderrerror log used before the configuration is read
-g "directives;"add global directives, e.g. -g "daemon off;"
-Vversion, compiler and configure arguments (modules built in)

Sources