1

当我apache尝试web.py使用mod_wsgi. 我已web.py在共享主机上成功安装,并且可以确认可以在本地导入它:

>>> import web
>>> web.application(('/', 'test'), globals())
<web.application.application instance at 0x1f8d3b0>

我还能够运行内置服务器并将页面成功提供给我的网站。

我可以确认该mod_wsgi模块也可以正常工作,apache因为我能够使用wsgi应用程序的手动编码来提供页面。

我尝试了文档http://webpy.org/install#apachemodwsgiImportError: No module named web上错误消息的建议方法,即添加:web.py

abspath = os.path.dirname(__file__)
sys.path.append(abspath)
os.chdir(abspath)

import web

我还在Fileshttp.conf 文件中添加了建议的标签,这似乎是多余的,因为我已经htdocs设置了目录,但无论如何。我的httpd.conf文件在下面,我已经重新启动了 apache,但仍然收到导入错误消息。

ServerRoot "/home/usr1/webapps/test/apache2"

LoadModule dir_module        modules/mod_dir.so
LoadModule env_module        modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module       modules/mod_mime.so
LoadModule rewrite_module    modules/mod_rewrite.so
LoadModule setenvif_module   modules/mod_setenvif.so
LoadModule wsgi_module       modules/mod_wsgi.so

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/usr1/webapps/test/logs combined
DirectoryIndex index.py
DocumentRoot /home/usr1/webapps/test/htdocs
ErrorLog /home/usr1/webapps/test/apache2/logs/error_test.log
KeepAlive Off
Listen 21708
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 5
WSGIDaemonProcess test processes=5 python-path=/home/usr1/webapps/test/lib/python3.1 threads=1
WSGIProcessGroup test
WSGIRestrictEmbedded On
WSGILazyInitialization On

<Directory /home/usr1/webapps/test/htdocs>
    AddHandler wsgi-script .py
</Directory>

<Files /home/usr1/webapps/test/htdocs/index.py>
   SetHandler wsgi-script
   Options ExecCgi FollowSymLinks
</Files>
4

1 回答 1

1

首先,您的 apache mod_wsgi 似乎是用 python 3 编译的,web.py 不支持。

你的 apache conf 看起来很像我在 Webfaction 上的那个,如果有一个带有 python 2.7 的 mod_wsgi 安装程序,你必须选择它而不是 python 3。

这是我典型的 conf 的样子:

ServerRoot "/home/username/webapps/projectname/apache2"

LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module       modules/mod_mime.so
LoadModule rewrite_module    modules/mod_rewrite.so
LoadModule alias_module modules/mod_alias.so
LoadModule wsgi_module       modules/mod_wsgi.so

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/username/logs/user/access_projectname.log combined
ErrorLog /home/username/logs/user/error_projectname.log
KeepAlive Off
Listen 21708
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
WSGIPythonOptimize 2
ThreadsPerChild 5
WSGIDaemonProcess projectname processes=5 threads=1
WSGIPythonHome /home/username/lib/python2.7 # your python home dir where libraries are installed
WSGIProcessGroup projectname
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIScriptAlias / /home/username/webapps/projectname/htdocs/code.py/
Alias /static /home/username/webapps/projectname/htdocs/static

这是示例 code.py

#!/usr/bin/env python
import os
import sys
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from app import app

if __name__ == "__main__":
    app.run()
else:
    application = app.wsgifunc()
于 2013-01-27T21:37:10.513 回答