nexcess / magento-turpentine

A Varnish extension for Magento.
GNU General Public License v2.0
519 stars 253 forks source link

Pagespeed / Turpentine #479

Closed GuillaumeEqui-Clic closed 9 years ago

GuillaumeEqui-Clic commented 10 years ago

I have a problem when I use pagespeed with turpentine. You can see the problem : http://table-de-massage-electrique.fr/fauteuil-specialise.html

<button type="button" title="Ajouter au panier" class="button btn-cart" onclick="setLocation('http://table-de-massage-electrique.fr/checkout/cart/add/uenc/aHR0cDovL3RhYmxlLWRlLW1hc3NhZ2UtZWxlY3RyaXF1ZS5mcjo4MDgwL3RhYmxlLW9zdGVvcGF0aGllLmh0bWw,/product/1/form_key/1lWjTPu3ZnpZePTf/')"><span><span>Ajouter au panier</span></span></button> become <button type="button" title="Ajouter au panier" class="button btn-cart" onclick="setLocation('http://table-de-massage-electrique.fr/checkout/cart/add/uenc/aHR0cDovL3RhYmxlLWRlLW1hc3NhZ2UtZWxlY3RyaXF1ZS5mcjo4MDgwL3RhYmxlLW9zdGVvcGF0aGllLmh0bWw,/product/1/form_key/<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

magenx commented 10 years ago

you have more problems than just a button, your cart page is cached with products... i think you need to configure your mod_pagespeed. read manuals, or google: "mod_pagespeed with varnish"

some users already have this problem too

aheadley commented 10 years ago

Please see the bit about Apache+mod_pagespeed on the wiki and let me know if that doesn't help.

GuillaumeEqui-Clic commented 10 years ago

I have disabled all filters PageSpeed ​​and I still have the problem. Thanks for your help. Version: 13: on

Filters hw Flushes html

Options aris True bu /ngx_pagespeed_beacon it 1396337978000 e 1 afg True afcci 3600000 afcl 500000 afcp /mnt/ngx_pagespeed_cache afc 16777216 ald /var/log/pagespeed alcb 16384 alcp 8192 l Core Filters ase True asle True xhv Powered By ngx_pagespeed

Domain Lawyer

GuillaumeEqui-Clic commented 10 years ago

I disable PageSpeed​​. It works.

I active PageSpeed. It doesn't work but if I go on port 8080, I see no difference.

I don't understand.

GuillaumeEqui-Clic commented 10 years ago

127.0.0.1 - - [01/Apr/2014:10:43:51 +0200] "GET /turpentine/esi/getBlock/method/esi/access/private/ttl/3600/hmac/949bd0281ed561a54d0a500f24cdf9ba0187131be3ef85b750567e092d0fd4c7/data/0kDIIJWoWtmGUW71uZryJJLPO6Gau9ZBfqUJr-kwJb79LhFLHF1CyuitR863-YR6tyf2zsiE83acEeiEIIZBjd1v2WKQ81EWQTDEGCH2AINiJa2iU6TebIXV5X.dG92q20haztFEVtyYfO-37zImZB8-Gs2iIyZPnWvbI5QpPjQ4hxoRpEhA1JtWDjbUKw8rfqhX2ukNoEnbj14Mzi2e2w5yQHXm55GT8esHz.YKPK07VYvTf--Dx3SeNylSs5V9153z9wcDuC0hYytZa9Uh-b66.azVgx7D.agvFdrRWCQk0GjWgavZ24uk4km5lmVnCp8UETlmDyKtRXe.JlB0T8WUWcAiX015Falvvy0R7GfCXhaBV9X-DRlOazVKc6eI-x5AnNTnQ1jKjwmZoj1MbA==/ HTTP/1.1" 200 1277 "http://table-de-massage-electrique.fr/fauteuil-specialise.html" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"

127.0.0.1 - - [01/Apr/2014:10:43:52 +0200] "GET / http: table-de-massage-electrique.fr turpentine esi getFormKey ttl 3600 method esi scope global access private HTTP/1.1" 404 5007 "http://table-de-massage-electrique.fr/fauteuil-specialise.html" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"

GuillaumeEqui-Clic commented 10 years ago

When I disable PageSpeed, I have : 127.0.0.1 - - [01/Apr/2014:11:21:14 +0200] "GET /turpentine/esi/getFormKey/ttl/3600/method/esi/scope/global/access/private/ HTTP/1.1" 200 47 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"

GuillaumeEqui-Clic commented 10 years ago

Do you have any idea about what can rewrite this request ? Thanks on advance.

GuillaumeEqui-Clic commented 10 years ago

It's better when I use Disallow to prevent pagespeed to rewrite url like /turpentine/esi/ but I don't have the form_key

pagespeed Disallow "*/turpentine/esi/*";

<li><a rel="nofollow" href="http://table-de-massage-electrique.fr/wishlist/index/add/product/61/form_key/%3Cesi:include%20src=" http:="" table-de-massage-electrique.fr="" turpentine="" esi="" getformkey="" ttl="" 3600="" method="" scope="" global="" access="" private="" "="">/" class="link-wishlist"&gt;Ajouter à la liste d'envies</a></li>

GuillaumeEqui-Clic commented 10 years ago

With pagespeed <li><a rel="nofollow" href="http://table-de-massage-electrique.fr/wishlist/index/add/product/61/form_key/%3Cesi:include%20src=" http:="" table-de-massage-electrique.fr="" turpentine="" esi="" getformkey="" ttl="" 3600="" method="" scope="" global="" access="" private="" "="">/" class="link-wishlist"&gt;Ajouter à la liste d'envies</a></li> Without pagespeed <li><a rel="nofollow" href="wishlist/index/add/product/61/form_key/QJ0yiI3LzxQKZAXH/" class="link-wishlist">Ajouter à la liste d'envies</a></li>

GuillaumeEqui-Clic commented 10 years ago

Pagespeed can't parse this type of url href="http://example.com/example/action/form_key/<esi:include src="http://example.com/getFormKey/"/>/" I can not use PageSpeed ​​behind varnish.

jeroenvermeulen commented 10 years ago

@TableDeMassageElectrique your last message is the first conclusion as my first one...

We may be able to workaround it by Restricting URLs I need to look into this.

GuillaumeEqui-Clic commented 10 years ago

I have a discuss in the Google Group : Magento CSRF Form Key Handling with Varnish / Pagespeed

jeroenvermeulen commented 10 years ago

I probably have found a workaround (sponsored by @itnova)

To the file app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl add this:

sub vcl_recv {
    #### Fix ESI URLs broken by Mod_PageSpeed
    if ( req.url ~ "https?: " ) {
        set req.http.Host = regsub( req.url, "^.*https?: ([\w\.\-]+).*$", "\1" );
        set req.url = regsub( req.url, "^.*https?: ([\w\.\-]+)", "" );
        set req.url = regsuball( req.url, " ", "/" );
    }
}

Now re-apply the Varnish config, and flush the Varnish cache. Or: update the Varnish startup-config and restart Varnish.

Example of a broken ESI URL: " http: www.domain.com store_code turpentine esi getFormKey ttl 86400 method esi scope global access private "

This fix cuts off the hostname and puts it in req.http.Host. In the remaining part the spaces are replaced by slashes.

GuillaumeEqui-Clic commented 10 years ago

Thank you for your tip. It's a very good idea. I tried but it doesn't work. I search why.

magenx commented 10 years ago

i would not worry about pagespeed at all, as long as you have gzip, expires, js/css merge enabled... for any images optimization is better to run "jpegtran" once, and then configure it for newly created images.... less cpu/resources wasted...

jeroenvermeulen commented 10 years ago

@magenx I totally agree. I don't link Mod_PageSpeed because it is a blackbox doing things you can do more precise by hand. But the customer is King, and they want to use it.

Elvinas commented 9 years ago

Hello everyone,

Can someone help me to configure varnish and turpentine on Magento CE to work properly. I have dedicated server where I have varnish installed and another website with ftp access that uses magento with turpentine extension.

No matter what I do I always get an error from turpentine:

Failed to apply the VCL to 185.5.54.139:6082: Failed to connect to Varnish on [185.5.54.139:6082]

This ip 185.5.54.139:6082 is from different server where I have varnish installed.

I used this tutorial - http://en.yrweb.fr/system/how-to/successful-varnish-implementation-with-your-magento-platform.html but I only changed differently in turpentine: My configuration Server list 185.5.54.139:6082

Backend server Backend Port 185.5.54.139 8080

Maybe I'm making mistake somewhere, can't make this work for two days....

Thank you in advance

siment commented 8 years ago

I would like to add to @jeroenvermeulen excellent suggestion and modify it somewhat. This regexp will allow you to use custom ports in your request url:

sub vcl_recv {
    #### Fix ESI URLs broken by Mod_PageSpeed
    if ( req.url ~ "https?: " ) {
        set req.http.Host = regsub( req.url, "^.*https?: ([\w\.\-]+(\s?\:[0-9]+)?).*$", "\1" );
        set req.url = regsub( req.url, "^.*https?: ([\w\.\-]+(\s?\:[0-9]*)?)", "" );
        set req.url = regsuball( req.url, " ", "/" );
    }
}

Otherwise this request URL:

http://www.example.com:6081/some/uri

Would become:

:6081/some/uri