1

I have a monit script that checks that nginx is up and running. One thing it does is checks for a file 'ping.txt'. I can view it in the browser, but what would cause the script to get a 301 redirect response back?

monit script snippet:

if failed port 80 protocol http and request '/ping.txt'

Here's what's in the nginx log:

127.0.0.1 - - [29/Feb/2012:20:59:58 +0000] "GET /ping.txt HTTP/1.1" 301 185 "-" "monit/5.2.5"
99miles
  • 361
  • 3
  • 6
  • 16

2 Answers2

1

Are you actually able to browse to ping.txt on the localhost? Maybe you need to try the LAN IP.

You can use a shell browser such as lynx or links2 to test. From your comment I see you may have configured it as a virtualhost. You mayneede to access the webpage using the hostname or full url, i.e. http://www.example.org/ping.txt.

In your example you try to access 127.0.0.1 hence your webserver returns a 301.

To change the host do something like:

check host host.example.com with address 192.0.43.10
if failed port 80 protocol http and request '/ping.txt'

Or leave out the address.

aseq
  • 4,550
  • 1
  • 22
  • 46
  • I'm able to browser to it using a domain hosted by the server. I don't have a browser on the server so not sure how exactly to check it on the server. – 99miles Mar 01 '12 at 00:26
  • See my updated answer. – aseq Mar 01 '12 at 00:36
  • I can hit the page fine from a browser on another machine. But the point of the file is simply for this command to check if nginx is running. ping.txt is used for nothing else. So I am needing to make this command work: 'if failed port 80 protocol http and request '/ping.txt'' -- I'm not sure how to change the hostname in that command. – 99miles Mar 02 '12 at 02:26
  • See my answer again :-) – aseq Mar 02 '12 at 03:05
  • Very strange, it continues to get a 301. – 99miles Mar 02 '12 at 03:19
  • Ah, I think it's a problem in my hosts files causing a 301 on every request... working on it. Thanks! – 99miles Mar 02 '12 at 03:24
0

I know this is old but I had the same problem and got to this question through googling "monit 301" the problem in my case after quite a lot of hair pulling was that "monit was not setting the hostname header when checking my server, thus it did not get directed to the correct vhost. You can add the hostname to the check with the hostheader directive eg:

check host www.mysite.co.uk with address wwwmysite.co.uk
  if failed
     port 443 protocol https
     and request / hostheader www.mysite.co.uk
     and status = 200
  then alert
squareborg
  • 592
  • 3
  • 14