bashで、ローカルpythonアプリが解析するコマンドラインオプションとしてURLに含まれるクエリ文字列または名前と値のペアを渡しながら、ローカルpythonスクリプトを呼び出すようにlighttpdを構成する最も簡単な方法は何ですか?
Example:
www.myapp.com/sendtopython/app1.py?Foo=Bar
results in the following occurring on the system.
>python app1.py Foo=Bar
www.myapp.com/sendtopython/app2.py?-h
results in the following occurring on the system.
>python app2.py –h
次に、lighttpdのインストールおよび設定スクリプトの例を示します。
#!/bin/bash
# Install and configure web console managed by lighttpd
# Suggested Amazon EC2 AMI : ami-0d729464
#
# The console installed into /opt/web-console and
# available on the http://_the_server_dns_/web-console
set -e -x
export DEBIAN_FRONTEND=noninteractive
function die()
{
echo -e "$@" >> /dev/console
exit 1
}
apt-get update && apt-get upgrade -y
apt-get -y install python
apt-get -y install unzip
apt-get -y install lighttpd
# web directory defaults to /var/www.
WEBDIR=/var/www/logs
mkdir $WEBDIR || die "Cannot create log directory."
PYTHON=`which python`
echo $?
if [ ! $? ]
then
echo "Python interpreter not installed or not found in system path!!!" >> /dev/console
echo "Exiting setup-instance..."
exit 1
fi
#Download web-console
FILE_DOWNLOAD_URL=http://downloads.sourceforge.net/web-console/web-console_v0.2.5_beta.zip
wget $FILE_DOWNLOAD_URL -O web-console.zip || die "Error downloading file web-console.zip"
# Install the web-console
INSTALL_DIR=/opt/web-console
mkdir $INSTALL_DIR
unzip -u -d $INSTALL_DIR web-console.zip || die "Error extracting web-console.zip"
chown www-data:www-data $INSTALL_DIR
# Configure lighttpd
cat > $INSTALL_DIR/webconsole.conf <<EOF
server.modules += ( "mod_cgi" )
alias.url += ( "/web-console/wc.pl" => "/opt/web-console/wc.pl" )
alias.url += ( "/web-console/" => "/opt/web-console/wc.pl" )
\$HTTP["url"] =~ "^/web-console/" {
cgi.assign = ( ".pl" => "/usr/bin/perl" )
}
EOF
ln -s $INSTALL_DIR/webconsole.conf /etc/lighttpd/conf-enabled/
/etc/init.d/lighttpd force-reload
exit 0