LMSouq
server-admin Open

How do I restart nginx only after the configuration test was successful on Ubuntu?

JA
jan
1 month ago
3 views
Problem Description
When I restart the nginx service on a command line on an Ubuntu server, the service crashes when a nginx configuration file has errors. On a multi-site server this puts down all the sites, even the ones without configuration errors. To prevent this, I run the nginx configuration test first: nginx -t After the test ran successful, I could restart the service: /etc/init.d/nginx restart **Or** only reload the nignx site configs without a restart: nginx -s reload Is there a way to combine those two commands where the restart command is conditional to the configuration test's result? I couldn't find this online and [the official documentation][1] on this is rather basic. I don't know my way around Linux that well, so I don't know if what I'm looking for is right in front of me or not possible at all. I'm using nginx v1.1.19. [1]: http://wiki.nginx.org/CommandLine

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base