Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Varnish: Misc

Re: Re: URL rewrite with Varnish

 

 

Varnish misc RSS feed   Index | Next | Previous | View Threaded


straightflush at gmail

Apr 3, 2012, 6:25 AM

Post #1 of 4 (1000 views)
Permalink
Re: Re: URL rewrite with Varnish

You should be able to easily rewrite the req.http.header value in vcl_recv

if (req.http.host == "mysite.domain.com") {
set req.http.host = "10.0.0.10";
}

To Rafal's point, this will pass the Host header of 10.0.0.10 to your
backend. Make sure you backend is configured to be port 8888

backend default {
.host = "127.0.0.1";
.port = "8888";
}

On Tue, Apr 3, 2012 at 9:07 AM, James Light <j.gareth.light [at] gmail>wrote:

> On Apr 3, 2012 8:53 AM, "RafaƂ Zawierta" <zawierta [at] gmail> wrote:
> >
> > Hello,
> >
> > Is it possible to handle such case: my webapp is running on
> http://10.0.0.10:8888/content/site/EN.html and whole site is on base url:
> http://10.0.0.10:8888/content/site/.
> >
> > I want to make my site available via Varnish on url:
> http://mysite.mydomain.com/ - I want to remove whole stuff after / from
> url.
> >
> > Rule:
> > sub vcl_recv {
> > if (req.http.host ~ "^(www\.)?mysite\.mydomain\.com$" ) {
> > set req.url = regsub(req.url, "^/content/site/", "/");
> > }
> > }
> >
> > isn't working at all.
> >
> > Regards
> > R.
> >
> > _______________________________________________
> > varnish-misc mailing list
> > varnish-misc [at] varnish-cache
> > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>
> Is your backend configured to respond to requests to that hostname and
> does it have a way to know that "/content/site" is aliased to "/" ?
> Sorry if I'm missing something but it seems like a rewrite rule on the
> backend is more appropriate for this sort of thing, no?
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc [at] varnish-cache
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>


zawierta at gmail

Apr 3, 2012, 6:35 AM

Post #2 of 4 (935 views)
Permalink
Re: Re: URL rewrite with Varnish [In reply to]

W dniu 3 kwietnia 2012 15:25 użytkownik AD <straightflush [at] gmail>napisał:

> You should be able to easily rewrite the req.http.header value in vcl_recv
>
> if (req.http.host == "mysite.domain.com") {
> set req.http.host = "10.0.0.10";
> }
>
> To Rafal's point, this will pass the Host header of 10.0.0.10 to your
> backend. Make sure you backend is configured to be port 8888
>
> backend default {
> .host = "127.0.0.1";
> .port = "8888";
> }
>
> On Tue, Apr 3, 2012 at 9:07 AM, James Light <j.gareth.light [at] gmail>wrote:
>
>> On Apr 3, 2012 8:53 AM, "Rafał Zawierta" <zawierta [at] gmail> wrote:
>> >
>> > Hello,
>> >
>> > Is it possible to handle such case: my webapp is running on
>> http://10.0.0.10:8888/content/site/EN.html and whole site is on base
>> url: http://10.0.0.10:8888/content/site/.
>> >
>> > I want to make my site available via Varnish on url:
>> http://mysite.mydomain.com/ - I want to remove whole stuff after / from
>> url.
>> >
>> > Rule:
>> > sub vcl_recv {
>> > if (req.http.host ~ "^(www\.)?mysite\.mydomain\.com$" ) {
>> > set req.url = regsub(req.url, "^/content/site/", "/");
>> > }
>> > }
>> >
>> > isn't working at all.
>> >
>> > Regards
>> > R.
>>
>

Sorry AD, but I'm not sure if your tip is helpful.
Once again: my backend server has ip 10.0.0.10, port 8888. It runs multiple
apps, so if I type http://10.0.0.10:8888 i get default site
http://10.0.0.10:8888/content/default/EN.html. Therefore I'd like varnish
to point me to /content/site/EN.html AND to remove "content/site/" from
URL.
That's why passing http.host won't work at all.

Regards


straightflush at gmail

Apr 3, 2012, 6:48 AM

Post #3 of 4 (949 views)
Permalink
Re: Re: URL rewrite with Varnish [In reply to]

Does your backend answer for the hostname mysite.domain.com in apache/nginx
? You didnt indicate that you have virtualhosts setup and what the
hostname header needs to be in order for your origin to respond properly.


On Tue, Apr 3, 2012 at 9:35 AM, Rafał Zawierta <zawierta [at] gmail> wrote:

>
>
> W dniu 3 kwietnia 2012 15:25 użytkownik AD <straightflush [at] gmail>napisał:
>
> You should be able to easily rewrite the req.http.header value in vcl_recv
>>
>> if (req.http.host == "mysite.domain.com") {
>> set req.http.host = "10.0.0.10";
>> }
>>
>> To Rafal's point, this will pass the Host header of 10.0.0.10 to your
>> backend. Make sure you backend is configured to be port 8888
>>
>> backend default {
>> .host = "127.0.0.1";
>> .port = "8888";
>> }
>>
>> On Tue, Apr 3, 2012 at 9:07 AM, James Light <j.gareth.light [at] gmail>wrote:
>>
>>> On Apr 3, 2012 8:53 AM, "Rafał Zawierta" <zawierta [at] gmail> wrote:
>>> >
>>> > Hello,
>>> >
>>> > Is it possible to handle such case: my webapp is running on
>>> http://10.0.0.10:8888/content/site/EN.html and whole site is on base
>>> url: http://10.0.0.10:8888/content/site/.
>>> >
>>> > I want to make my site available via Varnish on url:
>>> http://mysite.mydomain.com/ - I want to remove whole stuff after / from
>>> url.
>>> >
>>> > Rule:
>>> > sub vcl_recv {
>>> > if (req.http.host ~ "^(www\.)?mysite\.mydomain\.com$" ) {
>>> > set req.url = regsub(req.url, "^/content/site/", "/");
>>> > }
>>> > }
>>> >
>>> > isn't working at all.
>>> >
>>> > Regards
>>> > R.
>>>
>>
>
> Sorry AD, but I'm not sure if your tip is helpful.
> Once again: my backend server has ip 10.0.0.10, port 8888. It runs
> multiple apps, so if I type http://10.0.0.10:8888 i get default site
> http://10.0.0.10:8888/content/default/EN.html. Therefore I'd like varnish
> to point me to /content/site/EN.html AND to remove "content/site/" from
> URL.
> That's why passing http.host won't work at all.
>
> Regards
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc [at] varnish-cache
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>


varnish at mm

Apr 3, 2012, 7:01 AM

Post #4 of 4 (953 views)
Permalink
Re: Re: URL rewrite with Varnish [In reply to]

On Tue, Apr 03, 2012 at 03:35:31PM +0200, RafaƂ Zawierta wrote:
> W dniu 3 kwietnia 2012 15:25 uĆŒytkownik AD <straightflush [at] gmail>napisaƂ:
>
> > On Tue, Apr 3, 2012 at 9:07 AM, James Light <j.gareth.light [at] gmail>wrote:
> >
> >> On Apr 3, 2012 8:53 AM, "RafaƂ Zawierta" <zawierta [at] gmail> wrote:
> >> >
> >> > Hello,
> >> >
> >> > Is it possible to handle such case: my webapp is running on
> >> > http://10.0.0.10:8888/content/site/EN.html and whole site is on base
> >> > url: http://10.0.0.10:8888/content/site/.
> >> >
> >> > I want to make my site available via Varnish on url:
> >> > http://mysite.mydomain.com/ - I want to remove whole stuff after
> >> > / from url.
> >> >
> >> > Rule:
> >> > sub vcl_recv {
> >> > if (req.http.host ~ "^(www\.)?mysite\.mydomain\.com$" ) {
> >> > set req.url = regsub(req.url, "^/content/site/", "/");
> >> > }
> >> > }
> >> >
> >> > isn't working at all.
> >> >
> >> > Regards
> >> > R.
> >>
>
> Sorry AD, but I'm not sure if your tip is helpful.
> Once again: my backend server has ip 10.0.0.10, port 8888. It runs multiple
> apps, so if I type http://10.0.0.10:8888 i get default site
> http://10.0.0.10:8888/content/default/EN.html. Therefore I'd like varnish
> to point me to /content/site/EN.html AND to remove "content/site/" from
> URL.
> That's why passing http.host won't work at all.

I think your original example is doing the reverse of what you want. You
want to ADD /content/site/ to the incoming request from the client,
rather than remove it.

So, client requests / or /EN.html from your server; you want to do
something like

set req.url = "/content/site" + req.url;
# (not entirely sure of the syntax here... I think in 2.1 you can just
# put set req.url = "prefix" req.url; or you can use a regsub with
# "^" as the pattern to replace)

in your VCL in order to prepend "/content/site" to the request the
client sent, so that when it's sent to the backend it will look like a
request for /content/site/ or /content/site/EN.html.

You may also need to rewrite the req.http.Host header to what your
backend is expecting, if it's looking for a specific hosts entry.

The only complication you'll have is that if your backend generates
URLs, it will do so using the full path (/content/site/) - depending on
what the server is what application (if any) it's running, you might be
able to override that somehow.

_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc

Varnish misc RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.