当我尝试使用apache
运行web.py
应用程序时,我在mod_wsgi
错误日志文件中收到此错误。我已在我的共享主机上成功安装web.py
,我可以确认我可以在本地导入它:
>>> import web
>>> web.application(('/', 'test'), globals())
<web.application.application instance at 0x1f8d3b0>
我也可以运行内置服务器并成功将页面提供给我的网站。
我可以确认mod_wsgi
模块正在apache
中工作,因为我可以使用wsgi
应用的手动编码来提供网页。
我在ImportError: No module named web
文档http://webpy.org/install#apachemodwsgi上尝试了web.py
错误消息的建议方法,即添加:
abspath = os.path.dirname(__file__)
sys.path.append(abspath)
os.chdir(abspath)
import web
我还添加了http.conf文件中建议的Files
标记,这似乎是多余的,因为我已经设置了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>
答案 0 :(得分:1)
首先,你的apache mod_wsgi似乎是用python 3编译的,web.py不支持。
你的apache conf似乎与我在Webfaction上的那个很相似,如果mod_wsgi的安装程序有python 2.7,你必须选择它而不是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()