Dear,<br><br>It's not work for me, may be my configurations are wrong, could anyone help me please. Here's my configuration:<br><br><div style="margin-left: 40px; color: rgb(153, 51, 0);">sub vcl_recv {<br><br> # Host header check.<br>
# * Check if we recognize the domain used<br> # * Normalize host headers to limit cache usage<br> # * Rewrite URL for the virtual host monster<br> # Return an error for other requests.<br><br><br> # cache multimedia<br>
#if (req.request == "GET" && req.url ~ "\.(jpg|jpeg|gif|ico)$") {<br> # lookup;<br> #} <br><br> # cache CSS and JS files<br> if (req.request == "GET" && req.url ~ "\.(css|js)$") {<br>
lookup;<br> } <br><br> # do not cache POST requests<br> if (req.request == "POST") {<br> pipe;<br> }<br><br> if (req.request != "GET" && req.request != "HEAD") {<br>
<br> # figure out if you are allowed to purge stuff from cache<br> if (req.request == "PURGE") {<br> if (!client.ip ~ purge) {<br> error 405 "Not allowed.";<br> }<br>
lookup;<br> }<br><br> # else just pass it along<br> pipe;<br> }<br><br> if (req.http.Authenticate || req.http.Authorization) {<br> pass;<br> }<br>}<br><br>sub vcl_hit {<br> if (req.request == "PURGE") {<br>
set obj.ttl = 0s;<br> error 200 "Purged.";<br> }<br>}<br><br>sub vcl_miss {<br> if (req.http.If-Modified-Since) {<br> pass;<br> }<br><br> if (req.request == "PURGE") {<br> error 404 "Not in cache.";<br>
}<br>}<br><br>sub vcl_fetch {<br> if (!beresp.cacheable) {<br> return (pass);<br> }<br> if (beresp.http.Set-Cookie) {<br> return (pass);<br> }<br> return (deliver);<br> if (beresp.status == 301 || beresp.status == 302)<br>
{<br> set beresp.http.Location = regsub(beresp.http.Location, "^(\w+://[^/]+):\d+", "\1"); <br> }<br>}<br></div><br>Many thanks and regards.<br><br><div class="gmail_quote">On Wed, Sep 15, 2010 at 11:04 AM, Chris Cook <span dir="ltr"><<a href="mailto:crcook@gmail.com">crcook@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Awesome - the regex works perfectly. I think I'll keep it with the redirect since those were the only area I was observing a suboptimal URI. Thanks!<br>
<font color="#888888"><br>
-Chris<br>
</font><div><div></div><div class="h5"><br>
On Sep 14, 2010, at 11:22 PM, Michael Alger wrote:<br>
<br>
> On Tue, Sep 14, 2010 at 07:40:10PM -0400, Chris Cook wrote:<br>
>> I have an application that takes a URI that's submitted and spits back<br>
>> a different URI with a 302 redirect. The backend server translates<br>
>> this and sends back a new URI that contains the backend server port.<br>
>> I want to use Varnish to remove the backend server port before sending<br>
>> the request to the client.<br>
>><br>
>> Varnish receives - <a href="http://domain.com:8080/blah/stuff" target="_blank">http://domain.com:8080/blah/stuff</a><br>
>> Varnish makes it - <a href="http://domain.com/blah/stuff" target="_blank">http://domain.com/blah/stuff</a><br>
>><br>
>> What's the best way to do this? I assume it involves vcl_fetch and<br>
>> some variants of the beresp, but I haven't been able to figure it out<br>
>> yet.<br>
><br>
> I think you want something like this in vcl_fetch():<br>
><br>
> if (beresp.status == 301 || beresp.status == 302)<br>
> {<br>
> set beresp.http.Location = regsub(beresp.http.Location, "^(\w+://[^/]+):\d+", "\1");<br>
> }<br>
><br>
> Seems to work okay in our UAT environment. The regex is hopefully<br>
> matching any protocol specification (\w+://) and any hostname([^/]+).<br>
> A colon after the hostname followed by any number of digits will<br>
> then get dropped, but the request path should remain intact.<br>
><br>
> Technically you can use a Location: header in other responses, so if<br>
> that matters to you, you might want to change the if's to just a<br>
> check if beresp.http.Location is present.<br>
><br>
> _______________________________________________<br>
> varnish-misc mailing list<br>
> <a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br>
> <a href="http://lists.varnish-cache.org/mailman/listinfo/varnish-misc" target="_blank">http://lists.varnish-cache.org/mailman/listinfo/varnish-misc</a><br>
<br>
<br>
_______________________________________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br>
<a href="http://lists.varnish-cache.org/mailman/listinfo/varnish-misc" target="_blank">http://lists.varnish-cache.org/mailman/listinfo/varnish-misc</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Nguyen Dang Tung<br>