apache/nginx-执行从http请求获取params的程序
apache/nginx -execute program taking params from http request
我在Ubuntu 14.04上与Apache/Nginx一起使用VPS(在不同的时间(,并通过exec((在php中执行命令/程序。现在我知道了,我不需要Php来执行这些事情,比如说:
exec('whoami'); or
exec('myexec');
因为php在我的情况下只是作为附加层。那么,我可以使用apache/nginix从向它发出的http请求中获取数据吗(get,post..(,并将"pass"作为参数传递给特定的可执行程序,然后"返回输出"(纯文本(?比方说一个接收3个参数(4,5,+(并返回输出(9(的计算程序。
我已经看过这个ques,但它用Lua脚本说明了过程,而我正试图用c++做一些业余项目。目前我不知道如何进行,因为我只熟悉phpLAMP堆栈,如果我在某个地方错了,一点指导会很有帮助:(
您可能会在Web服务器中使用CGI,因此当请求某个URL时,它会为C++代码的输出提供服务。我不确定这是否可以被称为"好"的做法,但这是实现你想要的一种方法。有关详细信息,请查看此链接http://www.tutorialspoint.com/cplusplus/cpp_web_programming.htm
免责声明:我不是C++程序员,所以这可能实际上不起作用。
-
Web服务器配置
确保您的Web服务器支持CGI,并对其进行相应配置。Apache 2虚拟主机文件示例:
<Directory "/var/www/cgi-bin"> AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory> <Directory "/var/www/cgi-bin"> Options All </Directory>
-
示例C++程序
#include <iostream> using namespace std; int main () { cout << "Content-type:text/htmlrnrn"; cout << "<html>n"; cout << "<head>n"; cout << "<title>Hello World - First CGI Program</title>n"; cout << "</head>n"; cout << "<body>n"; cout << "<h2>Hello World! This is my first CGI program</h2>n"; cout << "</body>n"; cout << "</html>n"; return 0; }
编译以上代码并将可执行文件命名为cplusplus.cgi。将其放入/var/www/cgi-bin目录或Apache配置文件中配置的任何文件中。别忘了让它可执行(chmod 770 cplusplus.cgi(。现在,如果你访问网址www.example.org/cgi-bin/cplusplus,你应该会看到输出
Hello World! This is my first CGI program
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 为什么我的for循环不能正确获取argv
- 从python中调用C++函数并获取返回值
- 如何获取一个数字的前3位
- 获取字符串的长度并将其分配给数组
- 无法获取菜单选择以运行函数.C++
- C++使用params创建线程函数会导致转换错误
- 数组长度,为什么从命令行获取时不能使用它?
- Boost Spirit,获取迭代器内部语义动作
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 具有默认值的引用获取函数
- apache/nginx-执行从http请求获取params的程序