{"id":1087,"date":"2018-11-21T09:21:42","date_gmt":"2018-11-21T01:21:42","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=1087"},"modified":"2018-11-21T09:21:42","modified_gmt":"2018-11-21T01:21:42","slug":"nginx-status-explained","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=1087","title":{"rendered":"Nginx Status Explained"},"content":{"rendered":"<div class=\"entry-header\"><\/div>\n<div class=\"entry-content clearfix\">\n<p><a href=\"https:\/\/cdn.keycdn.com\/support\/wp-content\/uploads\/2016\/02\/nginx-status.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7543\" src=\"https:\/\/cdn.keycdn.com\/support\/wp-content\/uploads\/2016\/02\/nginx-status.png\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" srcset=\"https:\/\/cdn.keycdn.com\/support\/wp-content\/uploads\/2016\/02\/nginx-status-1024x512@2x.png 2048w, https:\/\/cdn.keycdn.com\/support\/wp-content\/uploads\/2016\/02\/nginx-status-300x150.png 300w, https:\/\/cdn.keycdn.com\/support\/wp-content\/uploads\/2016\/02\/nginx-status-768x384.png 768w, https:\/\/cdn.keycdn.com\/support\/wp-content\/uploads\/2016\/02\/nginx-status-1024x512.png 1024w, https:\/\/cdn.keycdn.com\/support\/wp-content\/uploads\/2016\/02\/nginx-status-300x150@2x.png 600w, https:\/\/cdn.keycdn.com\/support\/wp-content\/uploads\/2016\/02\/nginx-status-768x384@2x.png 1536w\" alt=\"nginx status\" width=\"2048\" height=\"1024\" \/><\/a><\/p>\n<p>This article explains the process used to check the current status of your Nginx server as well as how to use the <em>stub\u00a0status module<\/em> to gain more insight about your web server. Having the information provided by the Nginx status page can be useful to help determine information pertaining to the number of requests your server is currently receiving, the amount of active connections, etc.<\/p>\n<h2>Nginx \u2013 Starting, Stopping, and Restarting<\/h2>\n<p>Checking the Nginx status on the command line shows if the web server is currently running. On any\u00a0Debian\/RHEL\/Ubuntu\/CentOS Linux the following command can be used (\u201csudo\u201d not needed if the user has root permissions):<\/p>\n<pre># sudo service nginx status<\/pre>\n<p>If your Nginx server is currently running, the above command will return\u00a0<code>* nginx is running<\/code> and\u00a0<code>* nginx is not running<\/code> otherwise.<\/p>\n<p>Similar commands can also be used to start, stop or restart the server.<\/p>\n<pre>sudo service nginx stop\nsudo service nginx start\nsudo service nginx restart<\/pre>\n<h2>Configuring the Nginx Status Page<\/h2>\n<p><strong>Nginx<\/strong>\u00a0offers\u00a0a convenient\u00a0way to check the\u00a0<strong>server status<\/strong>\u00a0with the\u00a0module <em><a href=\"http:\/\/nginx.org\/en\/docs\/http\/ngx_http_stub_status_module.html\">stub_status_module<\/a><\/em>. With this\u00a0module, you\u2019ll be able to view important\u00a0information pertaining to your Nginx server on a status page.<\/p>\n<p>Most modern versions of\u00a0Nginx have this module already compiled, there\u2019s no need to compile it manually. You can check if the module is already compiled by using\u00a0this command:<\/p>\n<pre>nginx -V<\/pre>\n<p>If \u201c\u2013with-http_stub_status_module\u201d\u00a0appears within the <em>configure arguments<\/em>, then everything is ok. If you do not see this module upon running the above command, you may use the <code>\u2013with-http_stub_status_module<\/code> configuration parameter when building Nginx from source.<\/p>\n<pre>Note:\u00a0 \u00a0nginx -V 2&gt;&amp;1 | grep -o with-http_stub_status_module<\/pre>\n<p>As a next step, the Nginx config needs to be prepared. Go to the folder where your Nginx config is located and open the file with an editor (e.g. VI).<\/p>\n<pre>vi nginx.conf\n<\/pre>\n<p>The following code should go\u00a0inside the server\u00a0{} block as shown.<\/p>\n<pre>server {\n listen 80 default_server;\n # Define the document root of the server e.g \/var\/www\/html\n root \/var\/www\/html;\n    location \/nginx_status {\n    # Enable Nginx stats\n    stub_status on;<\/pre>\n<div class=\"inner-wrapper\">\n<div class=\"inner-wrapper\">\n<div class=\"grid-col grid-xl-9 grid-m-8 grid-s-8\">\n<div class=\"inner-wrapper\">\n<div class=\"nowiki\">\n<pre><tt>\u00a0 \u00a0 access_log off;<\/tt><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<pre>    # Only allow access from your IP e.g 1.1.1.1 or localhost #\n    allow 127.0.0.1;\n    allow 1.1.1.1\n    # Other request should be denied\n    deny all;\n}\n<\/pre>\n<p>The above code sets the status page to <em>on<\/em>\u00a0while also restricting access to it based on the defined allowed IPs. After the new config is saved, a\u00a0reload of Nginx is required in order to get the Nginx status. Reload Nginx with the following command.<\/p>\n<pre>service nginx reload\n<\/pre>\n<h2>Reading the Nginx Status Page<\/h2>\n<p>Once you have completed the above section, you now have access to\u00a0view the Nginx status page. To view the status page you now have two options.<\/p>\n<ul>\n<li>In a browser, navigate to your website url \/nginx_status (e.g. https:\/\/example.com\/nginx_status)<\/li>\n<li>Alternatively, you may use curl to retrieve the same information.\n<pre>curl https:\/\/example.com\/nginx_status<\/pre>\n<\/li>\n<\/ul>\n<p>The output of Nginx status will look similar to this:<\/p>\n<pre>Active connections: 43\nserver accepts handled requests\n 7368 7368 10993\nReading: 0 Writing: 5 Waiting: 38<\/pre>\n<p>Explanation:<\/p>\n<ul>\n<li><strong>Active connections<\/strong> \u2013 Open connections in total. One user\u00a0can have several\u00a0concurrent connections to a server.<\/li>\n<li>3 figures are shown.\n<ul>\n<li><em>All\u00a0accepted<\/em> connections.<\/li>\n<li><em>All\u00a0handled<\/em> connections, which normally equals to the total number of accepted connections.<\/li>\n<li>Total\u00a0number of handled\u00a0<em>requests.\u00a0<\/em><\/li>\n<\/ul>\n<\/li>\n<li><strong>Reading:\u00a0<\/strong>Nginx reads request headers<\/li>\n<li><strong>Writing:\u00a0<\/strong>Nginx reads request bodies, processes requests, or writes responses to a client<\/li>\n<li><strong>Waiting: <\/strong>Keep-alive connections. This number depends on the keepalive-timeout.<\/li>\n<\/ul>\n<p>With this module, you can now better monitor your Nginx status\u00a0to get a clearer picture of your server\u2019s connection \/ request stats.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This article explains the process used to check the current status of your Nginx server as well as how to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1087","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/1087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1087"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/1087\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}