nginx FastCGI-strip off the location prefix? -
i'm writing web application in python using web.py, spawn_fcgi , nginx.
let's have configuration block in nginx:
location / { include fastcgi.conf; fastcgi_pass 127.0.0.1:9001; }
if access, say, http://example.com/api/test
, fastcgi application receives /api/test
request location. web.py framework use location when determining class execute. example:
urls = ( "/api/.*", myclass )
the problem comes if need place script in location on website. example:
location /app { include fastcgi.conf; fastcgi_pass 127.0.0.1:9001; }
now, when access http://example.com/app/api/test
, fastcgi application gets /app/api/test
location.
it of course located anywhere: http://example.com/sloppy_admin/my%20web%20pages/app/api/test
example. :-)
i app relocatable, installing on other servers may necessitate (e.g. has share server else). seems bit hardheaded insist every server place in same "virtual subdirectory".
right now, workaround has been this:
url_prefix = "/app" # same nginx location parameter urls = ( url_prefix+"/api/.*",myclass )
the problems here 1) means script still needs edited per site (not horrible @ least inconvenient) , 2) url_prefix
variable has globally accessible entire collection of scripts - because example class or function may need access location need not include prefix.
i'm using custom python packages (e.g. directories containing init.py scripts) simplify managing different scripts make app, problem passing url_prefix parameter around. example:
app.py:
from myapp import appclass import web url_prefix = "/app" # same nginx location parameter urls = ( url_prefix+"/api/.*",appclass.myclass ) app = web.application(urls,globals()) if __name__ == "__main__": web.wsgi.runwsgi = lambda func, addr=none: web.wsgi.runfcgi(func, addr) app.run()
myapp/appclass.py:
class myclass: def get(self): global url_prefix # not work! return url_prefix
is there either nginx parameter cause path sent fastcgi relative location, or more elegant way handle in web.py?
the fastcgi.conf
file should have configuration options need. might want @ fastcgi_split_path_info
directive.
Comments
Post a Comment