configuring routes for web2py behind reverse proxy

341 views
Skip to first unread message

DeanK

unread,
Nov 5, 2013, 11:51:11 AM11/5/13
to web...@googlegroups.com
I have an instance of web2py running on nginx sitting behind an apache reverse proxy (soon to be nginx as well) so:


i have /myapp/default/landing set as the default application, controller, and function.  When i go directly to myserver1.otherdomain.com everything is fine, but if i go to www.mydomain.com/myapp all of my static files are unreachable because the relative paths point to www.mydomain.com/myapp/static/file where really it would have to be www.mydomain.com/myapp/myapp/static/file which is kind of ugly.  I am using URL() to create relative links.

I first though maybe the fact the the reverse proxy url and app names are the same was confusing regex or whatever was doing the rewrites, but that didn't seem to be the case.  I also started looking at routes.py and set BASE = 'myapp'.  That made parts of my site work, but things like login then didn't.


Anyone have experience setting a web2py app up behind a reverse proxy?  Thoughts? Thanks,

Dean

DeanK

unread,
Nov 7, 2013, 4:54:07 PM11/7/13
to web...@googlegroups.com
So I changed my reverse proxy set up to make debug a bit easier and maybe will get some suggestions from someone now:

I have an instance of web2py running on nginx sitting behind an apache reverse proxy so:


i have /myapp/default/index set as the default application, controller, and function.  When i go directly to myserver1.otherdomain.com everything works as expected. If i go to www.mydomain.com/link all of my static files are unreachable because the relative paths point to www.mydomain.com/myapp/static/file where really it would have to be www.mydomain.com/link/myapp/static/file.  I am using URL() to create relative links.

Looking at routes.py it seems like I should be setting BASE = 'link'

When I do this going to www.mydomain.com/link works (www.mydomain.com/link/ doesn't), but the site as a whole doesn't.  For example, if I try to log in, that page loses its static files.  Looking at what the static files now point to I get this which is clearly wrong:


Another example going to a simple page /myapp/default/learn



It looks like urls are getting re-written twice or something?  Does anyone have any suggestions on how to configure a web2py application to work behind a reverse proxy?

Dean

DeanK

unread,
Nov 14, 2013, 6:48:05 PM11/14/13
to web...@googlegroups.com
For anyone in the future trying to do this with Apache2 on Ubuntu:

ProxyHTMLInterp On
LogLevel Debug
ProxyHTMLLogVerbose On
ProxyPass /link/ http://my.server.com/
ProxyPassReverse /link/ http://my.server.com/

ProxyHTMLURLMap http://my.server.com /link/

<Location /stem/>
  ProxyPassReverse /
  SetOutputFilter  proxy-html
  ProxyHTMLURLMap http://my.server.com /link/
  ProxyHTMLURLMap / /link/
  ProxyHTMLURLMap  /link/ /link/
  RequestHeader    unset  Accept-Encoding
</Location>



On Tuesday, November 5, 2013 11:51:11 AM UTC-5, DeanK wrote:

Jason Lee

unread,
Apr 13, 2014, 1:24:20 PM4/13/14
to web...@googlegroups.com
What file am I supposed to add this to?

default, weby2py, default-sll?

Peter Lai

unread,
May 9, 2014, 1:40:36 AM5/9/14
to web...@googlegroups.com
To your Apache config
Reply all
Reply to author
Forward
0 new messages