Search code examples
gunicornpyramid

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


I have a Pyramid application that I am loading with Gunicorn. My ini file has the following:

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

I start Gunicorn witn:

gunicorn --paste ./development.ini

So my application is available at http://127.0.0.1:5900

What do I need to to do so my application is available in other path rather than / ,for example at http://127.0.0.1:5900/my_example

I saw the following posts: pyramid pserve in different root path than / and Pyramid: how to set SCRIPT_NAME in request.environ but I'm still not able to do it


Solution

  • Rutter is the right answer if you want all the incoming urls to just remove the prefix from them (for example, http://127.0.0.1:5900/my_example/foo/bar navigates to the /foo/bar route in your app). This seems to be what you're describing and the ini snippet in https://stackoverflow.com/a/43506460/704327 should be sufficient. Rutter will also prepare the environment correctly so that your app will generate the correct urls with the /my_example prefix when using request.route_path and request.route_url.