7 September 2026 · One command a day
How do I test my nginx config before reloading it?
nginx -t checks your nginx configuration for errors without touching the running server. It parses every file nginx would load, reports the first problem it finds, and tells you whether the config is safe to use. You reach for it every time you edit a server block, add a site, or renew a certificate, and before you ask nginx to reload.
The command
sudo nginx -t
nginx is the web server binary itself. The -t flag means test. It reads the main config file, follows every include line, checks the syntax, and then opens the files the config refers to, such as certificates and log files, to confirm they exist and are readable. It then exits without starting or reloading anything. You need sudo because some of those files, in particular private keys under /etc/letsencrypt, are only readable by root. Without it you may get a permission error that has nothing to do with your config.
What you will see
When everything is fine you get two lines:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
When something is wrong you get the problem first, then a failure line:
nginx: [emerg] unexpected "}" in /etc/nginx/sites-enabled/example.com:23
nginx: configuration file /etc/nginx/nginx.conf test failed
The important part is the file path and the number after the colon. That is the line where nginx gave up. The real mistake is often on the line above, usually a missing semicolon or an unclosed brace. Fix it, run the test again, and repeat until you see "test is successful". Only then run sudo systemctl reload nginx.
When to use it
- You have just added a new server block in
/etc/nginx/sites-availableand linked it intosites-enabled. Test before reloading so a typo does not take your other sites down with it. - You are changing a
proxy_passline to point at a new app on127.0.0.1. Testing confirms the syntax is right, even though it cannot tell you whether the app is actually listening. For that, see how to see which process is using a port. - nginx refused to start after a reboot and you need to know why. The test prints the same error that the service log buries.
Watch out for
A successful test does not mean your site will work. It means nginx can parse the config and open the files it names. It does not check that a domain resolves, that the upstream app is running, or that a certificate matches the hostname. It also does not check the config that is currently running, only the files on disk. So if you edit a file and forget to reload, the test passes but nothing changes. Treat nginx -t and systemctl reload nginx as a pair and always run them together.
Questions people ask
Does nginx -t restart or reload nginx?
No. It only reads and checks the files. The running server keeps serving traffic exactly as before until you reload it yourself.
What is the difference between nginx -t and nginx -T?
Lower case -t just tests. Upper case -T tests and then prints the whole merged configuration, with every included file expanded. That is useful when you cannot work out which file a setting is coming from.
On shared hosting you never see the nginx config, let alone test it. On a server you control, one command tells you whether a change is safe before anyone else finds out. You can get the same VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.
Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.
Affiliate link.