python CGI工作不正常

2024-04-19 11:39:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,我正在尝试编写我的第一个python cgi程序

我在sites-avilabe目录中编辑了default文件,现在是:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options ExecCGI Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                AddHandler cgi-script .py
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我编辑了这个部分:

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

就像现在的文件代码一样

然后我在var/www内创建了一个名为test.py的文件,它的内容如下:

#!/user/bin/python
import cgi
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head><title>MyFirst CGI :) </title></head>"
print "<body>"
print "<p>It works!!!</p>"
for i in range(5):
    print "<h1> hello world"
print "</body>"
print "</html>"

当然,apache正在运行

这就是我得到的:

内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。 请联系服务器管理员,网站管理员@127.0.0.1告诉他们错误发生的时间,以及你所做的任何可能导致错误的事情。 有关此错误的详细信息,请参阅服务器错误日志。

我还查了阿帕奇错误.log文件中没有与此脚本相关的内容


Tags: 文件服务器nonebinvarwww错误directory