Python CGI 可执行脚本下载/显示脚本代码
Python CGI executable script downloads / shows script code
我很久以前写的一个脚本 (getWords.py) 曾经可以在我的本地主机上执行 (http://local.example.com/getWords.py?query-string)
我的 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()
我启用了 ExecCGI
猫/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>
但脚本仍然强制下载 (FireFox) 或显示脚本代码 (Chrome)。
-rwxr-xr-x 1 username username 4794 Jul 14 17:15 getWords.py
知道我的本地主机出了什么问题吗?
$ apache2 -v
Server version: Apache/2.4.12 (Ubuntu)
Server built: Feb 4 2015 14:21:10
$ python -V
Python 2.7.3
在我的主机 (Webfaction) 上,它的 运行 在 http://example.com/getWords.py?query-string
你有没有在 apache2 中添加 cgi 处理程序
AddHandler cgi-script .py
https://www.linux.com/community/blogs/129-servers/757148-configuring-apache2-to-run-python-scripts
我很久以前写的一个脚本 (getWords.py) 曾经可以在我的本地主机上执行 (http://local.example.com/getWords.py?query-string)
我的 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()
我启用了 ExecCGI
猫/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>
但脚本仍然强制下载 (FireFox) 或显示脚本代码 (Chrome)。
-rwxr-xr-x 1 username username 4794 Jul 14 17:15 getWords.py
知道我的本地主机出了什么问题吗?
$ apache2 -v
Server version: Apache/2.4.12 (Ubuntu)
Server built: Feb 4 2015 14:21:10
$ python -V
Python 2.7.3
在我的主机 (Webfaction) 上,它的 运行 在 http://example.com/getWords.py?query-string
你有没有在 apache2 中添加 cgi 处理程序
AddHandler cgi-script .py
https://www.linux.com/community/blogs/129-servers/757148-configuring-apache2-to-run-python-scripts