我正在运行Ubuntu 11,我想设置一个简单的Web服务器,通过使用GET或POST参数调用本地脚本来响应http请求.这个脚本(已经编写)做了一些事情并创建了一个文件.该文件应该在URL上可用,然后Web服务器应该向另一个服务器发出http请求,告诉它下载创建的文件.
我该如何设置呢?我不是Linux的初学者,但我不会说我也很清楚.
我应该使用什么网络服务器?如何授予脚本访问本地资源以创建相关文件的权限?我不太关心安全性或任何东西,这是个人实验(我控制所涉及的所有计算机).我之前使用过apache,但我从来没有设置过它.
任何帮助,将不胜感激..
解决方法:
我安装了apache.如果你不这样做:sudo apt-get install apache2.
cd /usr/lib/cgi-bin
# Make a file and let everyone execute it
sudo touch test.sh && chmod a+x test.sh
然后将一些代码放在文件中.例如:
#!/bin/bash
# get today's date
OUTPUT="$(date)"
# You must add following two lines before
# outputting data to the web browser from shell
# script
echo "Content-type: text/html"
echo ""
echo "
Demo"echo "Today is $OUTPUT
"
echo "Current directory is $(pwd)
"
echo "Shell Script name is $0"
echo ""
如果一切顺利(就像它对我而言)你应该看到……
Today is Sun Dec 4 …
Current directory is /usr/lib/cgi-bin Shell
Shell Script name is /usr/lib/cgi-bin/test.sh
标签:shell,nginx,ubuntu,apache,webserver
来源: https://codeday.me/bug/20190930/1835673.html