WebFaction
Community site: login faq

I have WSGI application, which uses Pyramid, that I want to deploy under the path /foo of my domain.

In the Webfaction panel, I created the WSGI application in "Domains/websites > Applications", and using "Domains/websites > Websites", I added it with the URL path "/foo". I then change the file index.py for mod_wsgi to load my application, following what's written here http://docs.pylonsproject.org/projects/pyramid/en/latest/tutorials/modwsgi/index.html#modwsgi-tutorial and I can load my application in the browser.

There is one problem though: I'm using the functions provided by Pyramid to generate URL to the static resources of my application. Those functions use the PATH_INFO and SCRIPT_NAME WSGI environment variable to detect where the application is hosted, and how the URLs should look like. In the case of this deployment, PATH_INFO is empty '' and SCRIPT_NAME is index.py, which is not good, and so, my application completely fails to generate the correct URLs (I got http://xxx/index.py/static/file.css for instance, instead of http://xxx/foo/static/file.css).

So far, this is my mod_wsgi configuration directives:

WSGIDaemonProcess multani_foo processes=5 python-path=/home/multani/webapps/multani_foo/lib/python2.7 threads=1
WSGIProcessGroup multani_foo
WSGIRestrictEmbedded On
WSGILazyInitialization On

<Directory /home/multani/webapps/multani_foo/htdocs>
    AddHandler wsgi-script .py
</Directory>

I can wrap my WSGI application into a small function which sets the correct environment variables, but that seems hacky at best.

How to correctly deploy a WSGI application under a path so that the WSGI environment is correctly defined?

asked 01 Mar '12, 19:45

multani
336
accept rate: 0%


The problem is that when an application is mounted to a subpath, it is rewritten without that path when passed to the backend server. So the information that you are looking for is not available in the PATH_INFO and SCRIPT_NAME variables. The only way I can see for you to make this work would be to add the "foo/" prefix somewhere in your code when generating the URLs.

permanent link

answered 02 Mar '12, 02:28

todork
1.2k4
accept rate: 34%

Yes, that's the problem. Adding "foo/" is actually handled by the framework (Pyramid in this case) if it has the right information, which it lacks. There's no way I'm going to add the prefix everywhere in my code, though.

(02 Mar '12, 02:35) multani

You can try modifying the PATH_INFO and SCRIPT_NAME variables, after they have been received, and prefixing "foo/" there.

(02 Mar '12, 02:38) todork

I tried to change it (wrapping my app into another app which changes the environ dictionnary), but it didn't work. I don't remember the exact details though (got 404 answers), I will post this latter. It would be great if it worked out of the box, though.

(02 Mar '12, 03:42) multani

Sorry - this is a feature of our system. It helps in some cases but it creates problems in others (such as yours). I would suggest that you open a ticket if you want further help with this matter, as we could actually look at your app.

(02 Mar '12, 03:48) todork
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×222
×62
×55

question asked: 01 Mar '12, 19:45

question was seen: 3,076 times

last updated: 02 Mar '12, 03:48

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM