我正在尝试将金字塔应用推广到生产网站。
截至目前,我已经创建了应用程序放置在public_html中的env文件,如下所示:
[~/env] $
所以我输入了
$ ../bin/pserve production.ini,
但是,当我访问www.mydomain.com时,它仍然显示index.html。我该如何解决这个问题?
我使用的是CentOS 64bit + Apache + mod_wsgi。
设置如下:
Apache/2.2.24 (Unix)
mod_ssl/2.2.24
OpenSSL/1.0.0-fips
mod_wsgi/3.3
Python/2.6.6
mod_auth_passthrough/2.1
mod_bwlimited/1.4
FrontPage/5.0.2.2635 configured -- resuming normal operations
在我的production.ini文件中,如下所示
[app:main]
use = egg:ECommerce
reload_templates = false
debug_authorization = false
debug_notfound = false
debug_routematch = false
debug_templates = false
default_locale_name = en
mongodb.url = mongodb://my.ip.address
mongodb.db_name = mycart_demo
[filter:weberror]
use = egg:WebError#error_catcher
debug = false
;error_log =
;show_exceptions_in_wsgi_errors = true
;smtp_server = localhost
;error_email = janitor@example.com
;smtp_username = janitor
;smtp_password = "janitor's password"
;from_address = paste@localhost
;error_subject_prefix = "Pyramid Error"
;smtp_use_tls =
;error_message =
#[pipeline:main]
#pipeline =
# weberror
# ECommerce
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 8080
# Begin logging configuration
[loggers]
keys = root, ecommerce
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
[logger_ecommerce]
level = WARN
handlers =
qualname = ecommerce
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
# End logging configuration
我已经设法在生产网站上推出,但是,现在,它显示了500个内部服务器错误......
在apache error_log中,它显示:
[Sun Apr 07 23:17:47 2013] [alert] [client <ip_address>]
/home/vretnet9/public_html/.htaccess: WSGIScriptAlias not allowed here
所以我继续看看.htaccess
的.htaccess
Options +ExecCGI
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
WSGIScriptAlias ECommerce /home/vretnet9/modwsgi/env/pyramid.wsgi
WSGIDaemonProcess root processes=5 threads=1 display-name=%{GROUP}
WSGIProcessGroup root
WSGIApplicationGroup %{GLOBAL}
我不知道它是否应该实际调用.htaccess或者脚本应该与我的.conf中的脚本相同,而该脚本位于
/usr/local/apache/conf/userdata/std/1/$user/$domain/modwsgi.conf
modwsgi.conf的内容如下:
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess pyramid user=vretnet9 group=vretnet9 threads=4 \
python-path=/home/vretnet9/modwsgi/env/lib/python3.3/site-packages
WSGIScriptAlias /ECommerce /home/vretnet9/modwsgi/env/pyramid.wsgi
<Directory /home/vretnet9/modwsgi/env>
WSGIProcessGroup pyramid
Order allow,deny
Allow from all
</Directory>
修改 在apache error_log中,正在记录以下内容:
[Mon Apr 08 02:17:22 2013] [error] Traceback (most recent call last):
[Mon Apr 08 02:17:22 2013] [error] File
"/home/vretnet9/modwsgi/env/pyramid.wsgi", line 5, in <module>
[Mon Apr 08 02:17:22 2013] [error] from pyramid.paster import get_app,
setup_logging
[Mon Apr 08 02:17:22 2013] [error] File "/home/vretnet9/modwsgi/env/
lib/python3.3/site-packages/pyramid/paster.py", line 1, in <module>
[Mon Apr 08 02:17:22 2013] [error] import os
[Mon Apr 08 02:17:22 2013] [error] ImportError: No module named os
编辑#2
这是我在shell中运行时的结果:
[~/modwsgi/env]# python
Python 3.3.0 (default, Mar 27 2013, 09:31:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print (os.getcwd())
/home/vretnet9/modwsgi/env
答案 0 :(得分:1)
这不是你如何使用mod_wsgi + Apache将金字塔项目投入生产。我建议阅读The official documentation
运行../bin/pserve production.ini
时,它会在端口8080(在production.ini
中定义)启动粘贴HTTP服务器
理想情况下,您需要在新的虚拟环境中安装金字塔,然后配置mod_wsgi以使用 python实例。您必须在项目中添加.wsgi
脚本并配置mod_wsgi以在Apache启动时运行该脚本。
修改强>
ScriptAlias(以及所有相关部分)应该在你的modwsgi.conf中(确保你在实际的apache conf中导入modwsgi.conf)。
在该文件中,你应该定义你的PYTHONPATH和PYTHONHOME(特别是如果你有一个virtualenv)和你已经定义的其他东西(WSGIApplicationGroup,WSGIScriptAlias等)
重要 - 确保您的apache用户(apache)对.wsgi脚本具有读取执行权限。这意味着即使您的/ home目录也应该可以被apache访问。
我建议creatijg一个seaparate目录(比如/ opt / proj)来托管应用程序和另一个(比如环境的/ opt / env)。
这是我的pyramid.conf的样子。我有 Python 2.6 并在/ opt / save_project中保留我的项目(只有静态内容,如css,images,js和.wsgi脚本)。我的virtualenv是/ opt / pyra
WSGIPythonHome /opt/pyra
WSGIPythonPath /opt/pyra/lib/python2.6
<VirtualHost 31.1.1.22:8005>
DocumentRoot /opt/save_project
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIProcessGroup %{GLOBAL}
WSGIDaemonProcess pyramid user=apache group=apache \
python-path=/opt/pyra/lib/python2.6
WSGIScriptAlias / /opt/save_project/pyramid.wsgi
# Get the static and favicon.ico pages working by properly aliasing them
Alias /favicon.ico /opt/save_project/static/images/favicon.ico
Alias /static /opt/save_project/static
<Directory /opt/save_project>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
您可能会看到mod_wsgi docs了解更多信息