apache / incubator-pagespeed-mod

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

Trying to understand pagespeed Domain #2052

Open luison opened 3 years ago

luison commented 3 years ago

Hi. been using pagespeed for a while and trying to do some optimization now but just can't figure out completely how to authorize it to apply to some of our other domains.

Our setup is one with a Nginx reverse proxy server (nginx version: nginx/1.18.0) with pagespeed (V 14) installed handling SSL and proxying via upstream to apache servers via http on different containers.

We have pagespeed activated per domain basis with a specific:

pagespeed on; - per server domain

So mainproject.com pagespeed is working but we alss load some resources from two additional servers on our html like so:

Both domains are also in the same reverse proxy server:

https://assets.domain.com ---> internal IP port 80 via upstream - pagespeed not active on this nginx server https://image.domain.com ---> internal IP port 80 via upstream - pagespeed not active on this nginx server

At our maindomain.com project pagespeed config includes:

pagespeed Domain assets.domain.com; pagespeed Domain https://image.domain.com;

We've also tried including or not https protocol and MapOriginDomain rules but we always get: [Mon, 23 Nov 2020 19:53:16 GMT] [Info] [8695] No permission to rewrite https://image.domain.com/t/230x260/smart/gis/recursos/timeline_1995.jpg' Are we misunderstanding how we should activate pagespeed as we understood that the Domain directive should allow pagespeed to rewrite those too? Should they also be active with their own config on each of those internal CDN domains?

Pagespeed admin info page shows: Domain Lawyer http:// assets.domain.com/ Auth https://image.domain.com/ Auth

Thanks.

Lofesa commented 3 years ago

Hi great Luis =;-)) Well... you have a nginx proxy+pagespeed --> apache servers (main+pagespeed, image and assets), rigth? Then Apache(main+pagespeed) get html pages that contains urls from image and assets, rigth? I think that in (nginx proxy+pagespeed) pagespeed is not needed . And you must configure Apache servers+pagespeed in each and a downstream cache.

How Domain works: You have a SiteA and a SiteB. The site A generates html code that contains url from SiteB. In SiteA you have: pagespeed Domain http*://siteA (with this notation you cover the http and the https version) pagespeed Domain http:*//siteB Whit this config, pagespeed in SiteA can rewite (aka optimize) urls from SiteB, but can´t test if the rewrited url exits in SiteB, so if SiteB don´t run pagespeed module, when a request like https://siteB/some-image.jpg.ci.pagespeed.some-hash.web comes, it returns a 404 because don´t know nothing about pagespeed rewrited url. So, when you use pagespeed Domain is only for domains you know are running pagespeed module.

But you can try some like this:

pagespeed Domain http*://myproyect.domain.com pagespeed MapProxyDomain https://myproyect.domain.com/images http://images.domain.com pagespeed MapProxyDomain https://myproyect.domain.com/assets http://assets.domain.com

In this way all the content from http://images.domain.com are served under the url https://myproyect.domain.com/images. https://myproyect.domain.com/images this need to be a file folder to store files.

luison commented 3 years ago

Hi @Lofesa. That clarifies a bit but it does not reflect our setup-

We have nginx proxy+pagespeed --> apache servers (no pagespeed there).

Except for some static path (css, img) that are server locally by the proxy (bind mount of assets) the rest is all requested to the upstreams. For the main domain pagespeed seems to be working with css and some images. For example we have a php minifier for the css (apache upstream) and we can see that pagespeed is doing its "thing" there.

Our issue is that images and some other static content comes from other of our domains that work the same way but will never serve html) so the rewrite would need to be done at the maindomain and not on the imagedomain.

I've tried your option of an image rewrite via subdir but I still get the "No permission to rewrite" for the image domain on the logs.

Lofesa commented 3 years ago

So you have some like this in your nginx proxy cache + pagespeed:

server {
       port 443;
      name mainproject.domain.com;
      pagespeed on; (and all pagespeed config needed)
      all nginx proxy stuff; 
}
server {
       port 443;
      name images.domain.com;
      pagespeed on; (and all pagespeed config needed)
      all nginx proxy stuff; (included proxy_pass http://images.domain.com;)
}
server {
       port 443;
      name assets.domain.com;
      pagespeed on; (and all pagespeed config needed)
      all nginx proxy stuff; (included proxy_pass http://assets.domain.com;)
}

and then pagespeed do it stuff with proxied content? or maybe:

server {
       port 443;
      name mainproject.domain.com;
      pagespeed on; (and all pagespeed config needed)
      all nginx proxy stuff; 
      location /images/ {
            proxy_pass http://images.domain.com;
      }
      location /assets/ {
          proxy_pass http://assets.domain.com;
      }
}
luison commented 3 years ago

Hi again, thanks for the prompt reply. No, our setup is more like

nginx {
   all server stuff
   pagespeed config stuff
   pagespeed off
}

server {
       port 443;
      name mainproject.domain.com;
      pagespeed on; (and all pagespeed config needed)
       location /static - serving directly css, img, js      
      all nginx proxy stuff; 
}
server {
       port 443;
      name images.domain.com;
       pagespeed off;
       all nginx proxy stuff; (included proxy_pass http://images.domain.com;)
}
server {
       port 443;
      name assets.domain.com;
      pagespeed off; 
      all nginx proxy stuff; (included proxy_pass http://assets.domain.com;)
}

mainproject is proxying our backend for all php mainly images coming from images.domain.com

I guess by your message that my answer then is that if I wan pagespeed on maindomain to interact with resources coming from images.domain.com I need pagespeed on also on that nginx server proxy with its own config set (only images resizing in that case) correct?

Lofesa commented 3 years ago

I'm out of house for some hours, with mobile device. When returns to house I will see the whole message. The thing is, mainproject processes html code, and the others URLs contained in the html code processed by the mailproject. Right? Then you need pagespeed enabled in these other server blocks. And in the mainproject you need some like: pagespeed Domain http://.domain.com; This cover all version (http/Https) and all subdomains ( Are images and assets subdomains from the same domain that mainproject?)

In all other servers blocks yo need pagespeed on; pagespeed Domain http*://images.domain.com; Same for assets. Most of the pagespeed directives that are common to al servers, you can put it in the nginx http block, and not need to duplicate it.

In other hand, pagespeed off; can't disable pagespeed, or not totally. IPRO still working. To disable totally, you must use pagespeed unplugged;

P.S: I have send ths by email, but don´t see it here