我不知道这是甚至可能,但我可以显示通过web服务器的Linux命令的标准输出?
我想运行的命令是echo 'status' | nc localhost 4730 echo 'status' | nc localhost 4730 ,它返回一个string的齿轮人作业服务器的状态。
$echo 'status' | nc localhost 4730 function1 0 0 0 function2 0 0 1
我的服务器运行nginx。 我想打开一个URL,如http://domain.tld/gearman-status ,它应该通过运行该命令返回当前状态。
我应该在nginx的位置块做什么?
location /gearman-status { ? }
谢谢
nginx缺乏CGI支持,所以不能直接执行任何脚本。 您需要设置FastCGI服务器,并通过在您的location指令中使用fastcgi_pass从nginx调用它。 nginx wiki中有这样的FastCGI包装的例子 – 请参阅这个链接 。
你可以写一个小的PHP或Perl文件,并把它放在所需的path。 这个小文件将执行你想要的脚本或命令并打印输出。 你可以使用反引号`命令`来做到这一点。