通过Apache执行Python脚本

时间:2014-05-17 23:36:52

标签: python apache

我使用的是Python 3.4和Apache / 2.4.6

的Apache:

$ tail /etc/apache2/apache2.conf

ScriptAlias /python/ /var/www/python/
<Directory "/var/www/python">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    AddHandler cgi-script .py
    AddHandler default-handler .html .htm
</Directory>

CGI脚本:

$ ls -ld /var/www/python
drwxr-xr-x 2 root root 4096 May 17 17:30 /var/www/python/
$ ls -ld /var/www/python/my_script.py 
-rwxr-xr-x 1 root root 106 May 17 17:29 /var/www/python/my_script.py

然而,当我这样做时:

$ curl http://localhost/python/my_script.py

我明白了:

#!/opt/python/bin/python
print("Content-Type: text/html")
print()
print ("""<H1>Hello, world!</H1>""")

而不是我想要的HTML输出。

0 个答案:

没有答案