apache / incubator-pagespeed-mod

Apache module for rewriting web pages to reduce latency and bandwidth.
http://modpagespeed.com
Apache License 2.0
693 stars 157 forks source link

Nginx as reverse proxy not rewriting images - Works on second request #1635

Open debanjanbasu opened 7 years ago

debanjanbasu commented 7 years ago

This is the Website:

https://ec2-52-62-229-207.ap-southeast-2.compute.amazonaws.com

We are trying to achieve a Reverse Proxy with Caching and mod_pagespeed to optimize the webapge on: https://5lx4xixnt5h5s-site.azurewebsites.net

One the first load after restarting the server or purging the cache, the user is getting served with stale images.

Here is the Config file attached

nginx.txt

The problem is related to the MapProxyDomain I am pretty sure.

Can you guys please help to ensure an effective solution for the reverse proxy?

Here is what I believe is the issue and the fix. pagespeed Domain https://ec2-52-62-229-207.ap-southeast-2.compute.amazonaws.com;

pagespeed Domain https://*-cdn-webapp.azureedge.net;

    # pagespeed Domain https://*-cdn-storage.azureedge.net;
    # pagespeed Domain https://*-site.azurewebsites.net;
    # pagespeed MapOriginDomain https://girlfriend.staging.atlantic.digitalent-labs.link https://*-cdn-webapp.azureedge.net;
    # pagespeed MapOriginDomain https://girlfriend.staging.atlantic.digitalent-labs.link https://*-cdn-storage.azureedge.net;
    # pagespeed MapOriginDomain https://girlfriend.staging.atlantic.digitalent-labs.link https://*-site.azurewebsites.net;
    pagespeed MapRewriteDomain https://ec2-52-62-229-207.ap-southeast-2.compute.amazonaws.com https://*-cdn-webapp.azureedge.net;
    pagespeed MapRewriteDomain https://ec2-52-62-229-207.ap-southeast-2.compute.amazonaws.com https://*-cdn-storage.azureedge.net;
    pagespeed MapRewriteDomain https://ec2-52-62-229-207.ap-southeast-2.compute.amazonaws.com https://*-site.azurewebsites.net;
    # pagespeed MapProxyDomain https://girlfriend.staging.atlantic.digitalent-labs.link/cdnwebapp/ https://5lx4xixnt5h5s-cdn-webapp.azureedge.net/ https://girlfriend.staging.atlantic.digitalent-labs.link/cdnwebapp/;
    # pagespeed MapProxyDomain https://girlfriend.staging.atlantic.digitalent-labs.link/cdnstorage/ https://5lx4xixnt5h5s-cdn-storage.azureedge.net/ https://girlfriend.staging.atlantic.digitalent-labs.link/cdnstorage/;
    # pagespeed MapProxyDomain https://girlfriend.staging.atlantic.digitalent-labs.link/azurewebsite/ https://5lx4xixnt5h5s-site.azurewebsites.net/ https://girlfriend.staging.atlantic.digitalent-labs.link/azurewebsite/;
debanjanbasu commented 7 years ago

Use this URL to purge the cache if needed

https://ec2-52-62-229-207.ap-southeast-2.compute.amazonaws.com/pagespeed_admin/

jmarantz commented 7 years ago

What do you mean by "stale images"?

On Thu, Sep 21, 2017 at 8:32 PM, Debanjan Basu notifications@github.com wrote:

This is the Website:

https://ec2-52-62-229-207.ap-southeast-2.compute.amazonaws.com

We are trying to achieve a Reverse Proxy with Caching and mod_pagespeed to optimize the webapge on: https://5lx4xixnt5h5s-site.azurewebsites.net

One the first load after restarting the server or purging the cache, the user is getting served with stale images.

Here is the Config file attached

nginx.txt https://github.com/pagespeed/mod_pagespeed/files/1323131/nginx.txt

The problem is related to the MapProxyDomain I am pretty sure.

Can you guys please help to ensure an effective solution for the reverse proxy?

Here is what I believe is the issue and the fix. pagespeed Domain https://ec2-52-62-229-207.ap- southeast-2.compute.amazonaws.com;

pagespeed Domain https://

-cdn-webapp.azureedge.net http://cdn-webapp.azureedge.net; # pagespeed Domain https://-cdn-storage.azureedge.net;

pagespeed Domain https://

-site.azurewebsites.net http://site.azurewebsites.net; # pagespeed MapOriginDomain https://girlfriend.staging.atlantic.digitalent-labs.link https://girlfriend.staging.atlantic.digitalent-labs.link https://- cdn-webapp.azureedge.net;

pagespeed MapOriginDomain https://girlfriend.staging.

atlantic.digitalent-labs.link https:// -cdn-storage.azureedge.net http://cdn-storage.azureedge.net; # pagespeed MapOriginDomain https://girlfriend.staging.atlantic.digitalent-labs.link https://girlfriend.staging.atlantic.digitalent-labs.link https://- site.azurewebsites.net; pagespeed MapRewriteDomain https://ec2-52-62-229-207.ap- southeast-2.compute.amazonaws.com https:// -cdn-webapp.azureedge.net http://cdn-webapp.azureedge.net; pagespeed MapRewriteDomain https://ec2-52-62-229-207.ap-southeast-2.compute.amazonaws.com https://ec2-52-62-229-207.ap-southeast-2.compute.amazonaws.com https:// -cdn-storage.azureedge.net; pagespeed MapRewriteDomain https://ec2-52-62-229-207.ap- southeast-2.compute.amazonaws.com https://*-site.azurewebsites.net;

pagespeed MapProxyDomain https://girlfriend.staging.

atlantic.digitalent-labs.link/cdnwebapp/ https://5lx4xixnt5h5s-cdn- webapp.azureedge.net/ https://girlfriend.staging. atlantic.digitalent-labs.link/cdnwebapp/;

pagespeed MapProxyDomain https://girlfriend.staging.

atlantic.digitalent-labs.link/cdnstorage/ https://5lx4xixnt5h5s-cdn- storage.azureedge.net/ https://girlfriend.staging. atlantic.digitalent-labs.link/cdnstorage/;

pagespeed MapProxyDomain https://girlfriend.staging.

atlantic.digitalent-labs.link/azurewebsite/ https://5lx4xixnt5h5s-site. azurewebsites.net/ https://girlfriend.staging. atlantic.digitalent-labs.link/azurewebsite/;

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pagespeed/mod_pagespeed/issues/1635, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2kPX6kktJRFOsknyRdvOgiyMsj7RXuks5skwAvgaJpZM4PgFXI .

debanjanbasu commented 7 years ago

image

This is the response on the first request. It seems the files have not been actually cached yet. But the rewrite_domain is already done it's job. On the second request it starts to work perfectly.

Also the images being served are jpeg. However, the cache stores webp, and on second request the correct image is served.

debanjanbasu commented 7 years ago

image

Consecutive request

jmarantz commented 7 years ago

I wouldn't call that 'stale' I'd call that 'missing' :)

I can see that the URL works once PageSpeed rewrites it. But it should also work prior to the rewrite. On a cold cache, images get fetched & rewritten in response to the first request. However URLs are still rewritten based on the domain-mapping rules if rewrite_domains is enabled.

I have a crazy guess: you have your CDN origin-fetch configured to match the .pagespeed. URL pattern?

On Thu, Sep 21, 2017 at 9:32 PM, Debanjan Basu notifications@github.com wrote:

[image: image] https://user-images.githubusercontent.com/10209115/30725669-b928bac4-9f89-11e7-82b5-c1e3ab2d3d14.png

Consecutive request

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pagespeed/mod_pagespeed/issues/1635#issuecomment-331325919, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2kPfqhQinuo2QBb4MzCZzZyt25HGN4ks5skw4_gaJpZM4PgFXI .

debanjanbasu commented 7 years ago

I agree with you. It's simply a wrong URL, and mod_pagespeed is rewriting the url in the first go. How can I ensure that this works? What do I need to change in my nginx config to make this work please?

debanjanbasu commented 7 years ago

The CDN is a standard windows Azure CDN. I've tried with couple of other CDN providers and all are giving the same issue.