[BlueBream] proxy rewrite rule for nginx

Baiju M baiju.m.mail at gmail.com
Tue Sep 7 14:25:56 EDT 2010


On Tue, Sep 7, 2010 at 11:19 PM, Baiju M <baiju.m.mail at gmail.com> wrote:
> Hi,
>
> I was trying to deploy an application using nginx+gunicorn
> as given here:
> http://gunicorn.org/deploy.html
>
> But my "site" is located inside folder like this:
>
> http://127.0.0.1:8000/site
>
> I guess I need to use a "rewrite" directive before proxy_pass.
>
> In the gunicorn docs they used an "if" so I tried "rewrite" like this:
> rewrite ^/(.*)$ /site/++vh++http:domain.com:80/site/++$1 break;
>
> based on:
> http://wiki.zope.org/zope3/virtualhosting.html
>
> I also tried as given here, but it's not working:
> http://grok.zope.org/documentation/how-to/grok-virtual-hosting-and-nginx
>
> Any idea ?

I got help from Marius in IRC.

Just pasting the conversation here for reference:

11:23:05 PM) baijum: Any idea about this ?
https://mail.zope.org/pipermail/bluebream/2010-September/000609.html
(11:25:25 PM) mgedmin: baijum, can you clarify "does not work"?
(11:30:10 PM) baijum: mgedmin: now I am trying as given in grok's docs
(11:30:14 PM) baijum: I am getting
(11:30:15 PM) baijum: ValueError: Must have a path element '++' after
a virtual host directive.
(11:30:44 PM) baijum:
http://grok.zope.org/documentation/how-to/grok-virtual-hosting-and-nginx
(11:30:44 PM) mgedmin: ah, right, your regexp was wrong
(11:30:49 PM) mgedmin: you had rewrite ^/(.*)$
/site/++vh++http:domain.com:80/site/++$1 break;
(11:30:59 PM) mgedmin: you need rewrite ^(/.*)$
/site/++vh++http:domain.com:80/site/++$1 break;
(11:31:08 PM) mgedmin: or rewrite ^/(.*)$
/site/++vh++http:domain.com:80/site/++/$1 break;
(11:31:20 PM) mgedmin: so you don't get /foo rewritten to something
that ends in /++foo
(11:31:33 PM) mgedmin: it needs to be rewritten to .../++/foo
(11:34:24 PM) baijum: let me try
(11:39:30 PM) baijum: mgedmin: that worked, thanks ! but I think I
have some issue in my code, with some custom traverser expecting the
"site" in URL...
(11:40:02 PM) mgedmin: try rewrite ^/(.*)$ /site/++vh++http:domain.com:80/++/$1
(11:45:34 PM) baijum: mgedmin: that's not really traversal issue, URL
is "hard-coded" based on "site" location :)
(11:45:40 PM) baijum: ugly code:
(11:45:41 PM) baijum:     def baseurl(self):
(11:45:41 PM) baijum:         return "/%s/%s"%(self.site, self.name)
(11:45:55 PM) mgedmin: ah
(11:46:07 PM) mgedmin: when people do not use @@absolute_url, they lose
(11:46:24 PM) mgedmin: proper virtual hosting support
(11:47:08 PM) mgedmin: but still, the ++vh++.../site/++ is rarely needed
(11:47:11 PM) baijum: mgedmin: I will look into that later, thank you
very much !
(11:48:20 PM) mgedmin: if you're rewriting http://domain/A/x ->
http://localhost:8080/B/x, the rewrite rule generally is /A(/x)?$ ->
localhost:8080/B/++vh++domain:80/B/++$1
(11:48:46 PM) mgedmin: (where the regexp ensures that $1 starts with a
/ or is empty)
(11:49:15 PM) mgedmin: (IIRC zope's ++vh++ had issues with trailing
slashes after the final ++; not sure if it still has any)
(11:49:39 PM) baijum: oh.
(11:49:52 PM) mgedmin: also, I made a mistake
(11:50:00 PM) mgedmin: if you're rewriting http://domain/A/x ->
http://localhost:8080/B/x, the rewrite rule generally is /A(/x)?$ ->
localhost:8080/B/++vh++domain:80/A/++$1
(11:50:16 PM) mgedmin: in your use case I think A is empty
(11:51:03 PM) mgedmin: so the rule is supposed to be ^(/.*)?$ ->
/B/++vh++domain:80/++$1
(11:51:32 PM) mgedmin: this ++vh++ thing is insane :(
(11:51:45 PM) baijum: hmm..
(11:51:45 PM) mgedmin: as in insanely difficult to use
(11:53:01 PM) ***baijum noted down all these thing. will look into this later

Regards,
Baiju M


More information about the bluebream mailing list