في باش، ما هو أبسط وسيلة لتكوين لايت باد للاتصال بيثون السيناريو المحلي على أساس URL معين؟

StackOverflow https://stackoverflow.com/questions/1403672

  •  05-07-2019
  •  | 
  •  

سؤال

في باش، ما هو أبسط وسيلة لتكوين لايت باد للاتصال بيثون السيناريو المحلي بينما يمر أي سلسلة الاستعلام أو أزواج اسم القيمة المتضمنة URL كخيار سطر الأوامر للبرنامج بيثون المحلي لتحليل؟

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

وهنا مثال لايت باد تركيب والنصي التكوين.

#!/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
هل كانت مفيدة؟

المحلول

وحسن، لشيء واحد أود أن لا تعبث مع البرنامج النصي تثبيت، ولكن تشغيله مرة واحدة ثم قم بتحرير ملف التكوين لايت باد الناتج (webconsole.conf في حالتك).

وتحتاج بعد ذلك لتسجيل البرامج النصية بيثون لCGI، مثل يتم لبيرل في البرنامج النصي تثبيت. هل يمكن إضافة خط

cgi.assign = ( ".py" => "/usr/bin/python" )

وتحت المقابلة .PL الخط الذي من شأنه أن يجعل بيثون الخيار CGI آخر لل/ على شبكة الإنترنت وحدة / المسار (بحث عن مستندات لايت باد إذا كنت ترغب في تسجيل .py كما CGI في أي المسار) .

وبعد ذلك، لديك بيثون CGI النصي app1.py، app2.py، ... يجب أن <م> الامتثال إلى المواصفات CGI، والتي إذا ما أذكر correclty يمر المعلمات URL كما متغيرات البيئة. وبالتالي لا يمكنك ببساطة استخدام sys.argv. أنا متأكد من أن هناك وحدة بيثون أن يفعل استخراج المعلمة بالنسبة لك. (في بيرل، وحدة CGI لينكولن شتاين قادرة على حد سواء الحياة الفطرية والقيادة وسائط الخط، لكنني لست متأكدة من بيثون).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top