You simply use t and c flags followed by config file
sudo nginx -tc /etc/nginx/nginx.conf
This can give you output like this when ok:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
t flag according to man nginx means : Do not run, just test the configuration file. nginx checks the configuration file syntax and then tries to open files referenced in the configuration file.
c flag means: Use an alternative configuration file. the config file path should come after the c flag.
Why you should use this instead of restart? or reload? because when you do sudo service nginx restart and your config file is broken you’ll affect the whole server and if you have multiple websites that means all sites go down possibly because of some little curly boi ; . reload might not do anything when there is error. to be safe always test config before reloading or restarting. even if you do simple changes to main nginx config or sites configs.