贴纸配置中的基本路径

时间:2011-05-05 23:39:44

标签: python wsgi pyramid paster dotcloud

我正在尝试将一些金字塔代码部署到dotcloud。遗憾的是,某些路径的映射方式与本地paster部署中的映射方式不同。当我通过paster serve ...运行本地服务器的开发配置时,我可以访问配置为的静态文件:

config.add_static_view('static', 'appname:static')

但是在dotcloud服务器上,当脚本通过以下wsgi.py

运行时
import os, sys
from paste.deploy import loadapp
current_dir = os.path.dirname(__file__)
application = loadapp('config:production.ini', relative_to=current_dir)

在错误的目录中搜索静态内容。它应该放在/home/dotcloud/current/static/pylons.css

中,而不是/home/dotcloud/current/appname/static/pylons.css

是否有部分wsgi配置可以定义基目录?我错过了什么?该应用程序通过nginx / uwsgi运行。

我尝试加载config:../production.inirelative_to=current_dir + '/appname',但这并未改变任何内容。

1 个答案:

答案 0 :(得分:4)

在DotCloud上,以/static开头的网址由nginx直接处理,而不是由uwsgi处理。这意味着您的代码永远不会看到这些请求:它们将直接从您的应用程序的static/子目录中提供。

一种可能的解决方法是设置从staticappname/static的符号链接。

如果您不希望使用这样的符号链接来混淆您的存储库,则可以改为使用postinstall脚本:

#!/bin/sh
# This creates the symlink required by DotCloud to serve static content from nginx
ln -s ~/current/appname/static ~/current/static

符号链接很流畅,但是postinstall脚本让你有机会在文件中放入注释,以解释它的用途: - )

DotCloud的未来版本可能提供“裸配置”切换,其中nginx配置将不包括任何特殊路径处理,以防您不需要它们。

同时,如果您想查看DotCloud服务的nginx默认配置,您只需dotcloud ssh到您的服务,并检查/etc/nginx/sites-enabled/default

相关问题