{"id":1665,"date":"2016-12-29T16:54:59","date_gmt":"2016-12-29T21:54:59","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=1665"},"modified":"2017-01-12T18:30:22","modified_gmt":"2017-01-12T23:30:22","slug":"check_http-returns-403-forbidden-on-fresh-nagios-installation","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2016\/12\/check_http-returns-403-forbidden-on-fresh-nagios-installation\/","title":{"rendered":"check_http returns 403 Forbidden on fresh Nagios installation"},"content":{"rendered":"<p>I recently installed a Nagios server on a new CentOS 7 virtual machine (on Virtual Box).<\/p>\n<p>One of the default checks included upon installation is a check on localhost to confirm that the HTTP server is responding. (First I had to install the <code>check_http<\/code> plugin, see <a href=\"https:\/\/osric.com\/chris\/accidental-developer\/2016\/12\/missing-nagios-plugins-in-centos-7\/\">previous post<\/a>.) The Nagios web interface reports a warning for this check:<\/p>\n<p><code>HTTP WARNING: HTTP\/1.1 403 Forbidden - 5261 bytes in 0.001 second response time <\/code><\/p>\n<p>This is unexpected, since I can request the same page in a browser, which returns the Apache Welcome page.<\/p>\n<p>When I run the check manually I get the same result, as expected:<\/p>\n<p><code># \/usr\/lib64\/nagios\/plugins\/check_http -H localhost<br \/>\nHTTP WARNING: HTTP\/1.1 403 Forbidden - 5261 bytes in 0.001 second response time |time=0.000907s|;;;0.000000 size 5261B;;;0<\/code><\/p>\n<p>I checked with curl:<\/p>\n<p><code># curl http:\/\/localhost<\/code><\/p>\n<p>This returns the HTML source of the Apache Welcome page. It looks like it is working, right? But looking at the headers returned by the Apache server also shows <code>403 Forbidden<\/code>:<\/p>\n<p><code># curl -I http:\/\/localhost<br \/>\nHTTP\/1.1 403 Forbidden<br \/>\n...<\/code><\/p>\n<p>The Apache Welcome page gives some hints about this behavior:<\/p>\n<blockquote><p><strong>Are you the Administrator?<\/strong><\/p>\n<p>You should add your website content to the directory \/var\/www\/html\/.<\/p>\n<p>To prevent this page from ever being used, follow the instructions in the file \/etc\/httpd\/conf.d\/welcome.conf.<\/p><\/blockquote>\n<p>The <code>\/etc\/httpd\/conf.d\/welcome.conf<\/code> file begins with the following comments and directive:<\/p>\n<pre><code>#\r\n# This configuration file enables the default \"Welcome\" page if there\r\n# is no default index page present for the root URL.  To disable the\r\n# Welcome page, comment out all the lines below.\r\n#\r\n# NOTE: if this file is removed, it will be restored on upgrades.\r\n#\r\n&lt;LocationMatch \"^\/+$\"&gt;\r\n    Options -Indexes\r\n    ErrorDocument 403 \/.noindex.html\r\n&lt;\/LocationMatch&gt;<\/code><\/pre>\n<p>The Apache config is specifying that if there is no index page for the document root, return the Welcome page as an error document with a 403 HTTP status code.<\/p>\n<p>Once I added a basic HTML file at <code>\/var\/www\/html\/index.html<\/code>, Nagios returned a success message:<\/p>\n<p><code>HTTP OK: HTTP\/1.1 200 OK - 549 bytes in 0.001 second response time<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Nagios check_http command reports a warning on localhost on a fresh Nagios installation, even though I can request http:\/\/localhost in a browser. The Welcome page displayed by Apache is an error document though, with HTTP status code 403 Forbidden, rather than 200 OK.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[422],"tags":[73,215,348],"class_list":["post-1665","post","type-post","status-publish","format-standard","hentry","category-sysadmin","tag-apache","tag-curl","tag-nagios"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=1665"}],"version-history":[{"count":4,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1665\/revisions"}],"predecessor-version":[{"id":1689,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1665\/revisions\/1689"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=1665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=1665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=1665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}