简体   繁体   English

Python CGI可执行脚本下载/显示脚本代码

[英]Python CGI executable script downloads / shows script code

A script I wrote long ago (getWords.py) used to be executable at my localhost ( http://local.example.com/getWords.py?query-string ) 我很久以前写的脚本(getWords.py)以前可以在我的本地主机( http://local.example.com/getWords.py?query-string )上执行。

My python script starts like this : 我的python脚本是这样开始的:

#!/usr/bin/env python
# chmod 755 getWords.py

print "Content-type: text/html\n\n"

import os, sys, time, cgi, cgitb, re
import json, hashlib, gzip, urllib, urllib2
cgitb.enable()

I have enabled ExecCGI 我启用了ExecCGI

cat /etc/apache2/sites-available/example cat / etc / apache2 / sites-available / example

<VirtualHost *:80>
    ServerName local.example.com
    DocumentRoot /home/username/Dropbox/vhosts/example/
    <Directory /home/username/Dropbox/vhosts/example>
        Options +Indexes +FollowSymLinks +MultiViews +ExecCGI
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog /var/log/apache2/error.example.log
    LogLevel warn
    CustomLog /var/log/apache2/access.example.log combined
</VirtualHost>

But still the script force downloads (FireFox) or shows the script code (Chrome). 但是脚本仍然可以强制下载(FireFox)或显示脚本代码(Chrome)。

-rwxr-xr-x 1 username username 4794 Jul 14 17:15 getWords.py

Any idea what is wrong on my localhost ? 知道我的本地主机有什么问题吗?

$ apache2 -v
Server version: Apache/2.4.12 (Ubuntu)
Server built:   Feb  4 2015 14:21:10
$ python -V
Python 2.7.3

On my host (Webfaction), its running at http://example.com/getWords.py?query-string 在我的主机(Webfaction)上,其运行在http://example.com/getWords.py?query-string

Did u add cgi handler in apache2 您是否在apache2中添加了cgi处理程序

AddHandler cgi-script .py AddHandler cgi-script .py

https://www.linux.com/community/blogs/129-servers/757148-configuring-apache2-to-run-python-scripts https://www.linux.com/community/blogs/129-servers/757148-configuring-apache2-to-run-python-scripts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM