{"id":608,"date":"2024-11-08T11:50:43","date_gmt":"2024-11-08T11:50:43","guid":{"rendered":"https:\/\/249host.com\/tutorials\/?p=608"},"modified":"2024-11-08T12:01:32","modified_gmt":"2024-11-08T12:01:32","slug":"nginx-with-systemctl-to-start-stop-restart","status":"publish","type":"post","link":"https:\/\/249host.com\/tutorials\/nginx-with-systemctl-to-start-stop-restart\/","title":{"rendered":"Start, Stop, and Restart Nginx with systemctl"},"content":{"rendered":"<p class=\"h3\">Introduction:<\/p>\n<p>Nginx with systemctl command is used to start,stop and restart services.<\/p>\n<p>Nginx is a powerful server application that routes network traffic. It&#8217;s often used as a reverse proxy server but can also be configured as a <a href=\"https:\/\/www.squarebrothers.com\/dedicated-server-india\/\" target=\"_blank\" rel=\"noopener\">web server.<\/a><\/p>\n<p>One of the most common operations you will encounter is starting, stopping, and restarting the Nginx service.<\/p>\n<p><strong>In this tutorial, learn how to start, stop, and restart the Nginx service.<\/strong><\/p>\n<p class=\"h3\">Prerequisites<\/p>\n<ul class=\"wp-block-list\">\n<li>A system with Nginx installed and configured.<\/li>\n<li>Access to a terminal window or command line.<\/li>\n<li>A user account with\u00a0<strong>sudo<\/strong>\u00a0or\u00a0<strong>root<\/strong>\u00a0privileges.<\/li>\n<li>An existing SSH connection to a remote system (if you&#8217;re working remotely).<\/li>\n<\/ul>\n<h2 id=\"ftoc-heading-1\" class=\"wp-block-heading ftwp-heading\">Start, Stop, and Restart Nginx with systemctl<\/h2>\n<p>Managing Nginx requires knowing how to <a href=\"https:\/\/249host.com\/tutorials\/nginx-with-systemctl-to-start-stoprestart\/\">start, stop, and restart the service.<\/a> These commands are essential when applying new changes or when troubleshooting issues.<\/p>\n<p><strong>systemd<\/strong> is the default service manager for modern versions of Linux distributions. The <strong>systemd<\/strong> manager functions through <strong><code>systemctl<\/code><\/strong>, a base Linux command. That means it can be used for any Linux service, including Nginx.<\/p>\n<p>The sections below show how to run these commands and control the Nginx service using <strong><code>systemctl<\/code><\/strong>.<\/p>\n<h3 id=\"ftoc-heading-2\" class=\"wp-block-heading ftwp-heading\">How to View Status of Your Nginx Server<\/h3>\n<p>Nginx runs as a service on your server. It actively runs in the background, even if it is not visible on the screen. You can display the status of the Nginx service by entering the following command in a terminal window:<\/p>\n<pre>sudo systemctl status nginx<\/pre>\n<p>The system will switch to status mode and display information about the Nginx service. The status shows as one of the following:<\/p>\n<ul class=\"wp-block-list\">\n<li>If the service is running (active), the third line shows a green\u00a0<strong>active (running)<\/strong>\u00a0status.<\/li>\n<li>If Nginx is not running, it will appear\u00a0<strong>inactive<\/strong>\u00a0in white.<\/li>\n<li>If something went wrong and Nginx couldn&#8217;t load, you&#8217;ll see a red status\u00a0<strong>failed<\/strong>, with some information about the failure.<\/li>\n<\/ul>\n<p>Press <strong><code>q<\/code><\/strong> to reactivate the Bash prompt and exit the status mode.<\/p>\n<h3 id=\"ftoc-heading-3\" class=\"wp-block-heading ftwp-heading\">Stop and Start Nginx with systemctl<\/h3>\n<p><strong><code>systemctl<\/code><\/strong> can be used to start and stop the Nginx service.<\/p>\n<p>To stop Nginx, run the following command:<\/p>\n<pre>sudo systemctl stop nginx<\/pre>\n<p><span id=\"span-87-157\" class=\"ct-span oxy-stock-content-styles\">To start Nginx, execute the <strong><code>systemctl<\/code><\/strong> command with the <strong><code>start<\/code><\/strong> option:<\/span><\/p>\n<pre>sudo systemctl start nginx<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-611 size-full\" src=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/11\/nginx-command.png\" alt=\"Nginx with systemctl\" width=\"801\" height=\"346\" srcset=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/11\/nginx-command.png 801w, https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/11\/nginx-command-300x130.png 300w, https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/11\/nginx-command-768x332.png 768w\" sizes=\"auto, (max-width: 801px) 100vw, 801px\" \/><\/p>\n<h3 id=\"ftoc-heading-4\" class=\"wp-block-heading ftwp-heading\">How to Restart Nginx with systemctl<\/h3>\n<p>There are several ways to restart the Nginx service. The methods differ depending on whether the configuration changes are minor or major.<\/p>\n<h4 id=\"ftoc-heading-5\" class=\"wp-block-heading ftwp-heading\">Gracefully Restart Nginx with systemctl<\/h4>\n<p>When refreshing Nginx after changing the configuration, reload the service gracefully. That shuts down old processes and restarts new ones with the new configuration.<\/p>\n<p>Use the <strong><code>systemctl<\/code><\/strong> Linux command to reload the Nginx service:<\/p>\n<pre>sudo systemctl reload nginx<\/pre>\n<h4 id=\"ftoc-heading-6\" class=\"wp-block-heading ftwp-heading\">Force Restart Nginx<\/h4>\n<p>For major configuration changes, forcefully restart Nginx. This closes the whole service and subprocesses and restarts the whole package.<\/p>\n<p>Enter the following command:<\/p>\n<pre>sudo systemctl restart nginx<\/pre>\n<h4 id=\"ftoc-heading-7\" class=\"wp-block-heading ftwp-heading\">Restart vs. Reload Nginx<\/h4>\n<p>The <strong><code>reload<\/code><\/strong> command keeps the Nginx server running as it reloads updated configuration files. If Nginx notices a syntax error in the configuration files, the reload is aborted, and the server keeps running based on old configuration files. <strong>Reloading is safer than restarting Nginx<\/strong>.<\/p>\n<p>The <strong><code>restart<\/code><\/strong> command shuts down the server, including all related services, and powers it on again. Restart Nginx only when making significant configuration updates, such as changing ports or interfaces. This command will force shut down all worker processes.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Nginx with systemctl command is used to start,stop and restart services. Nginx is a powerful server application that routes network traffic. It&#8217;s often used as a reverse proxy server but can also be configured as a web server. One of the most common operations you will encounter is starting, stopping, and restarting the Nginx [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,1],"tags":[73,71,72],"class_list":["post-608","post","type-post","status-publish","format-standard","hentry","category-general","category-linux","tag-restart","tag-start","tag-stop"],"_links":{"self":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts\/608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/comments?post=608"}],"version-history":[{"count":8,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts\/608\/revisions"}],"predecessor-version":[{"id":617,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts\/608\/revisions\/617"}],"wp:attachment":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/media?parent=608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/categories?post=608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/tags?post=608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}