/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
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:
sudo nginx -T 2>/dev/null | grep -n "client_max_body_size"Command-line switches
| Switch | Does |
|---|---|
| -t | test the configuration and exit |
| -T | test, then dump the full configuration |
| -q | with -t, print only errors |
| -s reload | reopen | stop | quit | signal the running master process |
| -c file | use another configuration file |
| -p prefix | set the prefix path (relative paths are resolved from it) |
| -e file | stderr | error log used before the configuration is read |
| -g "directives;" | add global directives, e.g. -g "daemon off;" |
| -V | version, compiler and configure arguments (modules built in) |
Sources
Related pages
cheat sheets · nginxnginx cheat sheet: commands, server blocks, locations and proxyingnginx cheat sheet: test and reload, logs, server blocks, location matching order, reverse proxy headers, HTTPS redirects, static files and caching headers.errors · nginxnginx: [emerg] host not found in upstream "backend"nginx fails with host not found in upstream when a proxy_pass or upstream hostname does not resolve at startup, common with Docker service names. Fixes.errors · nginxnginx: "proxy_pass" cannot have URI part in location given by regular expressionnginx rejects proxy_pass http://host/path/ inside a regex location, named location, if or limit_except. Remove the URI part and change the path with rewrite.