paster配置中的基本路径

2 投票
1 回答
868 浏览
提问于 2025-04-16 17:05

我正在尝试把一些Pyramid代码部署到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/appname/static/pylons.css 找到,而不是 /home/dotcloud/current/static/pylons.css

有没有什么wsgi配置的部分可以定义基础目录?我漏掉了什么吗?这个应用是通过 nginxuwsgi 运行的。

我尝试加载 config:../production.inirelative_to=current_dir + '/appname',但这些都没有改变任何东西。

1 个回答

4

在DotCloud上,以 /static 开头的链接是由nginx直接处理的,而不是uwsgi。这意味着你的代码根本看不到这些请求:它们会直接从你应用的 static/ 子目录中提供服务。

一个可能的解决办法是设置一个符号链接,从 static 指向 appname/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

撰写回答