在与 / 不同的路径中使用 Gunicorn 加载金字塔应用程序

Load a Pyramid App with Gunicorn in a different path than /

我有一个使用 Gunicorn 加载的 Pyramid 应用程序。我的 ini 文件包含以下内容:

[app:main]
use = egg:my_example
...
[server:main]
use = egg:gunicorn
host = localhost
port = 5900
workers = 1
worker_class = gevent

我开始使用 Gunicorn:

gunicorn --paste ./development.ini

所以我的申请可以在 http://127.0.0.1:5900

我需要做什么才能使我的应用程序在其他路径而不是 / 中可用,例如 http://127.0.0.1:5900/my_example

我看到了以下帖子: pyramid pserve in different root path than / Pyramid: how to set SCRIPT_NAME in request.environ 但我还是做不到

Rutter 是正确的答案,如果您希望所有传入的 url 只从它们中删除前缀(例如,http://127.0.0.1:5900/my_example/foo/bar 导航到您应用程序中的 /foo/bar 路由)。这似乎就是您所描述的, 中的 ini 片段应该足够了。 Rutter 还将正确准备环境,以便您的应用在使用 request.route_pathrequest.route_url.

时生成带有 /my_example 前缀的正确网址