Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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"
share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
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 1 '12 at 0:26
    
See my updated answer. –  aseq Mar 1 '12 at 0: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 2 '12 at 2:26
    
See my answer again :-) –  aseq Mar 2 '12 at 3:05
    
Very strange, it continues to get a 301. –  99miles Mar 2 '12 at 3:19

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.