nginx:我可以在特定 url 上显示 shell 命令的输出吗?

Mri*_*ria 7 nginx gearman

我不确定这是否可行,但我可以通过网络服务器显示 linux 命令的标准输出吗?

我要运行的命令是echo 'status' | nc localhost 4730返回一个带有齿轮工作服务器状态的字符串。

$echo 'status' | nc localhost 4730
function1      0       0       0
function2      0       0       1
Run Code Online (Sandbox Code Playgroud)

我的服务器正在运行 nginx。我想打开一个像http://domain.tld/gearman-status这样的 URL ,它应该通过运行该命令返回当前状态。

我应该在 nginx 的位置块中放什么来做到这一点?

location /gearman-status {
  ?
}
Run Code Online (Sandbox Code Playgroud)

谢谢

Ale*_*exD 4

nginx缺乏 CGI 支持,因此它无法直接执行任何脚本。您需要设置 FastCGI 服务器并通过在指令中nginx使用来调用它。nginx wiki 中有此类 FastCGI 包装器的示例 - 请参阅此链接fastcgi_passlocation