跳转至

execute: NGINX Execute 模块

安装

您可以在任何基于 RHEL 的发行版中安装此模块,包括但不限于:

  • RedHat Enterprise Linux 7、8、9 和 10
  • CentOS 7、8、9
  • AlmaLinux 8、9
  • Rocky Linux 8、9
  • Amazon Linux 2 和 Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-execute
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nginx-module-execute

通过在 /etc/nginx/nginx.conf 顶部添加以下内容来启用模块:

load_module modules/ngx_http_execute_module.so;

本文档描述了 nginx-module-execute v1.6.1,于 2018 年 5 月 21 日发布。


介绍

ngx_http_execute_module 用于远程执行命令并返回结果。

配置示例:

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
            command on;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

用法: view-source:http://192.168.18.22/?system.run[command] command 可以是任何系统命令。您想要使用的命令取决于 nginx 运行时的权限。

view-source:http://192.168.18.22/?system.run[ifconfig]

如果使用浏览器发送命令,请确保使用“查看源代码”以查看格式化的输出。 另外,您也可以使用一些工具,例如 Postman、Fiddler。

需要用户交互或不断更新输出的命令(例如 top)将无法正常运行,因此请不要为此提交 bug。

GitHub

您可以在 nginx-module-execute 的 GitHub 仓库 中找到有关此模块的其他配置提示和文档。