|
List Info
Thread: getting the base url behind mod_proxy
|
|
| getting the base url behind mod_proxy |

|
2007-05-24 13:08:40 |
Hi All,
I was using cherrypy (3.0) behind mod_proxy and apache. I
have the
tools.proxy.on set to True and the x-http-* values are in
the environ.
This is a WSGI application and uses the cherrypy wsgi
server.
In my case the application is setup in the following
configuration:
http://hostname.com/blog
<-- Redirects to cherrypy application
http://127.0.0.1:8080
<-- cherrypy application
My issue is that my application tries to establish full urls
using the
x-http values, but the 'blog' portion is missing. I have
solved this
rather easily by adding a config item where you can specify
the base
url, but it would be better if I could use a function as I
did before
(using paste).
I am rather new to cherrypy so I apologize if I am missing
anything
obvious. In other words, I am more than happy to continue to
RTFM
Thanks!
Eric
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: getting the base url behind
mod_proxy |

|
2007-05-24 13:29:16 |
On 5/24/07, Eric Larson <ionrock gmail.com> wrote:
[snip]
> http://hostname.com/blog
<-- Redirects to cherrypy application
> http://127.0.0.1:8080
<-- cherrypy application
>
> My issue is that my application tries to establish full
urls using the
> x-http values, but the 'blog' portion is missing. I
have solved this
> rather easily by adding a config item where you can
specify the base
> url, but it would be better if I could use a function
as I did before
> (using paste).
Have you tried mounting your application in CherryPy at
/blog?
cherrypy.tree.mount(BlogApp(), '/blog', yourconfig)
That is what I do with my own apps hosted via
Apache+mod_proxy, and it
works fine. I can happily use cherrypy.url() to build
correct URLs.
> I am rather new to cherrypy so I apologize if I am
missing anything
> obvious. In other words, I am more than happy to
continue to RTFM
No apology necessary. Welcome to the CP community!
Christian
http://www.dowski.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: getting the base url behind
mod_proxy |
  United States |
2007-05-24 13:42:36 |
Eric Larson wrote:
> I was using cherrypy (3.0) behind mod_proxy and apache.
I have the
> tools.proxy.on set to True and the x-http-* values are
in the environ.
> This is a WSGI application and uses the cherrypy wsgi
server.
>
> In my case the application is setup in the following
configuration:
>
> http://hostname.com/blog
<-- Redirects to cherrypy application
> http://127.0.0.1:8080
<-- cherrypy application
>
> My issue is that my application tries to establish full
urls using the
> x-http values, but the 'blog' portion is missing. I
have solved this
> rather easily by adding a config item where you can
specify the base
> url, but it would be better if I could use a function
as I did before
> (using paste).
>
> I am rather new to cherrypy so I apologize if I am
missing anything
> obvious. In other words, I am more than happy to
continue to RTFM
*cough*
>>> import cherrypy
>>> help(cherrypy.tools.proxy.callable)
Help on function proxy in module cherrypy.lib.cptools:
proxy(base=None, local='X-Forwarded-Host',
remote='X-Forwarded-For',
scheme='X-Forwarded-Proto')
Change the base URL (scheme://host[:port][/path]).
For running a CP server behind Apache, lighttpd, or
other HTTP
server.
If you want the new request.base to include path info
(not just the
host),
you must explicitly set base to the full base path, and
ALSO set
'local'
to '', so that the X-Forwarded-Host request header
(which never
includes
path info) does not override it.
cherrypy.request.remote.ip (the IP address of the
client) will be
rewritten if the header specified by the 'remote' arg is
valid.
By default, 'remote' is set to 'X-Forwarded-For'. If you
do not
want to rewrite remote.ip, set the 'remote' arg to an
empty string.
So, if you want the new request.base to include path info
(like
'/blog'), you must explicitly set the 'base' argument to the
full base
path and ALSO set the 'local' arg to ''. In your example:
[global]
tools.proxy.on: True
tools.proxy.base: "http://hostname.com/bl
og"
tools.proxy.local: ""
I can kind of see a case for separating those two concerns;
that is, we
could have written the tool to take a "/blog"
argument and then
automatically combine that with the X-Forwarded-Host header
value. I
think we did not do that because both host and mount point
are sort of
"deployment-y". But as it's written now, there's
no real way to support
using the same mount point for multiple virtual hosts.
Hmmm...perhaps in
a future version we could assume:
if not absurl(base):
base = urljoin(local, base)
Robert Brewer
System Architect
Amor Ministries
fumanchu amor.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: getting the base url behind
mod_proxy |

|
2007-05-24 19:41:11 |
On 5/24/07, Robert Brewer <fumanchu amor.org> wrote:
>
> Eric Larson wrote:
> > I was using cherrypy (3.0) behind mod_proxy and
apache. I have the
> > tools.proxy.on set to True and the x-http-* values
are in the environ.
> > This is a WSGI application and uses the cherrypy
wsgi server.
> >
> > In my case the application is setup in the
following configuration:
> >
> > http://hostname.com/blog
<-- Redirects to cherrypy application
> > http://127.0.0.1:8080
<-- cherrypy application
> >
> > My issue is that my application tries to establish
full urls using the
> > x-http values, but the 'blog' portion is missing.
I have solved this
> > rather easily by adding a config item where you
can specify the base
> > url, but it would be better if I could use a
function as I did before
> > (using paste).
> >
> > I am rather new to cherrypy so I apologize if I am
missing anything
> > obvious. In other words, I am more than happy to
continue to RTFM
>
> *cough*
>
> >>> import cherrypy
> >>> help(cherrypy.tools.proxy.callable)
> Help on function proxy in module cherrypy.lib.cptools:
>
Wow, I can't believe I always seem to forget where a manual
is close
at hand! Thanks for the reminder
> proxy(base=None, local='X-Forwarded-Host',
remote='X-Forwarded-For',
> scheme='X-Forwarded-Proto')
> Change the base URL (scheme://host[:port][/path]).
>
> For running a CP server behind Apache, lighttpd, or
other HTTP
> server.
>
> If you want the new request.base to include path
info (not just the
> host),
> you must explicitly set base to the full base path,
and ALSO set
> 'local'
> to '', so that the X-Forwarded-Host request header
(which never
> includes
> path info) does not override it.
>
> cherrypy.request.remote.ip (the IP address of the
client) will be
> rewritten if the header specified by the 'remote'
arg is valid.
> By default, 'remote' is set to 'X-Forwarded-For'.
If you do not
> want to rewrite remote.ip, set the 'remote' arg to
an empty string.
>
>
> So, if you want the new request.base to include path
info (like
> '/blog'), you must explicitly set the 'base' argument
to the full base
> path and ALSO set the 'local' arg to ''. In your
example:
>
> [global]
> tools.proxy.on: True
> tools.proxy.base: "http://hostname.com/bl
og"
> tools.proxy.local: ""
>
> I can kind of see a case for separating those two
concerns; that is, we
> could have written the tool to take a
"/blog" argument and then
> automatically combine that with the X-Forwarded-Host
header value. I
> think we did not do that because both host and mount
point are sort of
> "deployment-y". But as it's written now,
there's no real way to support
> using the same mount point for multiple virtual hosts.
Hmmm...perhaps in
> a future version we could assume:
>
> if not absurl(base):
> base = urljoin(local, base)
>
FWIW, I was using Ian Bicking's algorithm for finding the
base url
specified in PEP 333, so I would lean towards some means of
adhering
to that pattern if I were to add some sort of urljoin. With
that said,
adding the tools.proxy.base does the trick as far as I'm
concerned.
> Robert Brewer
> System Architect
> Amor Ministries
> fumanchu amor.org
>
Thanks for all the help!
Eric
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-4]
|
|