首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Monit检查URL跟随重定向

Monit检查URL跟随重定向
EN

Server Fault用户
提问于 2012-03-20 14:43:27
回答 1查看 2.7K关注 0票数 2

我希望使用monit来监视我的网站。我希望它把它作为一个外部用户对待它,所以正在测试的网址,但它似乎不遵循重定向。内容检查正在重定向的html上执行。

代码语言:javascript
复制
#request works:
if failed url http://www.sharelatex.com/blog/posts/future.html content == "301"

#request fails
if failed url http://www.sharelatex.com/blog/posts/future.html content == "actual content"

找出如何让网址检查跟随30X将是很好的。

EN

回答 1

Server Fault用户

回答已采纳

发布于 2012-03-20 15:02:31

尽管我在monit手册页中没有看到一个选项使它遵循重定向,但我认为通过显式测试重定向的元素。首先测试重定向头,然后测试目标页面的内容,从而实现相同的目标。

(这是响应,包括从请求重定向到sharelatex )

代码语言:javascript
复制
HTTP/1.1 301 Moved Permanently       <---- response code here
Server: nginx/0.7.65
Date: Tue, 20 Mar 2012 22:04:48 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://www.sharelatex.com/blog/posts/future.html   <---- target location here

我会用下面这样的东西;

代码语言:javascript
复制
check host www.sharelatex.com with address www.sharelatex.com
IF FAILED URL http://www.sharelatex.com/blog/posts/future.html content == "301 Moved Permanently" 
    then alert
IF FAILED URL http://www.sharelatex.com/blog/posts/future.html content == "Location: https://www.sharelatex.com/blog/posts/future.html"
    then alert
IF FAILED URL https://www.sharelatex.com/blog/posts/future.html content == "ShareLaTeX"         
    then alert

所以打破它..。这两行检查HTTP://页面重定向是否正确,并检查它是否为重定向提供了正确的目标。

代码语言:javascript
复制
check host www.sharelatex.com with address www.sharelatex.com
IF FAILED URL http://www.sharelatex.com/blog/posts/future.html content == "301 Moved Permanently" then alert
IF FAILED URL http://www.sharelatex.com/blog/posts/future.html content == "Location: https://www.sharelatex.com/blog/posts/future.html" then alert  

然后测试你是否被重定向到正确的地方,并得到一些内容.

然后,下面的行,有效地显式地执行重定向,并在https://www.sharelatex.com/blog/posts/future.html上测试HTTPS页面的内容

代码语言:javascript
复制
 IF FAILED URL https://www.sharelatex.com/blog/posts/future.html content == "ShareLaTeX" then alert   

我猜第一批命令每页会产生一堆(2倍)的请求,所以可能值得将它们组合在一起.

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/371576

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档