【问题标题】:Error in starting apache2 server while configuring for python配置 python 时启动 apache2 服务器时出错
【发布时间】:2011-05-03 17:50:09
【问题描述】:

您好,我正在尝试为 python 配置 apache2 服务器,我使用此命令安装 apache2:

sudo apt-get install apache2
cd /etc/apache2/mods-enabled/
sudo ln -s ../mods-available/mod_python.load mod_python.load
cd /etc/apache2/sites-available/
sudo gedit default

将默认文件编辑为:

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

                AddHandler mod_python .py
                PythonHandler mod_python.publisher
                PythonDebug On

                # Uncomment this directive is you want to see apache2's
                # default start page (in /apache2-default) when you go to /
                #RedirectMatch ^/$ /apache2-default/
    </Directory>

后来我用了这个命令:

sudo /etc/init.d/apache2 restart

我遇到了一个错误:

* Starting web server apache2                                                  apache2: Syntax error on line 204 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/mod_python.load: LoadModule takes two arguments, a module name and the name of a shared object file to load it from

当我尝试使用 cat 命令查看 mod_python.load 中存在的链接时,我得到了LoadModule python_module / usr/lib/apache2/modules/mod_python.so

请帮帮我。

继续.. 现在我遇到了一个新错误 先生,我已经放置了一个包含代码的文件 hello.py

#!/usr/bin/python
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'

/var/www 中名为 cgi-bin 的文件夹中 当我使用

在 apache2 上运行它时

http://localhost/cgi-bin/hello.py

我收到了这个错误

The requested URL /cgi-bin/hello.py was not found on this server.
Apache/2.2.14(Ubuntu)Server at localhost Port 80

【问题讨论】:

  • 不要输入{}。单击显示{} 图标的按钮。
  • 您可以cat /etc/apache2/mods-enabled/mod_python.load 并将输出添加到您的问题中吗?此外,您不必自己搞乱符号链接...只需运行 a2enmod ${modname}
  • 对不起,我是新手,不知道如何显示代码 sn-p,好吧,我在 mod_python.load 上执行了命令 cat,这就是我得到的:LoadModule python_module / usr/lib/apache2/modules/mod_python.so
  • @Bhuvan raj - 前导 / 和模块路径的其余部分之间似乎有一个空格。有没有?如果是这样,请删除空格并重试...
  • 哦,是的,有一个空格,我的错!我想这一定是你曾经遇到过的愚蠢的高度!我真的很抱歉你的时间:-/非常感谢它现在工作:) :) 顺便说一句,我可以运行用 python 编写的 cgi 程序对吗??

标签: python apache2 mod-python


【解决方案1】:

看起来在前导 / 和模块路径的其余部分之间有一个空格。有没有?如果是这样,请删除空格并重试...

【讨论】:

    猜你喜欢
    • 2020-09-20
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 2012-12-19
    • 2012-04-18
    • 2011-01-30
    • 1970-01-01
    相关资源
    最近更新 更多