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

"pagespeed" directive "MapProxyDomain" not recognized or too many arguments #1960

Open Chathu07 opened 4 years ago

Chathu07 commented 4 years ago

When I try to localize facebook, twitter, pinterest.com scripts and style sheets, pagespeed giving me following error. This site uses letsencrypt SSL and I already use Jetpack CDN.

"pagespeed" directive "MapProxyDomain https://localhost/pageSpeed/facebook" not recognized or too many arguments in /var/www/mydomain.com/pagespeed-nginx.conf:31

I have added these configurations to nginx server block.

#site SSL.
pagespeed SslCertDirectory                    /etc/letsencrypt/live/mydomain.com/;
pagespeed SslCertFile                         /etc/letsencrypt/live/mydomain.com/fullchain.pem;

pagespeed Domain                              https://www.mydomain.com;
pagespeed MapOriginDomain                     https://localhost https://www.mydomain.com;

pagespeed LoadFromFileMatch                   "^https://[^/]*.mydomain.com/" "/var/www/mydomain.com/htdocs/";

#pagespeed MapRewriteDomain c0.wp.com *.mydomain.com;
#pagespeed MapRewriteDomain i1.wp.com *.mydomain.com;
#pagespeed MapRewriteDomain i0.wp.com *.mydomain.com;
#pagespeed MapRewriteDomain i2.wp.com *.mydomain.com; 

pagespeed Domain                             *.wp.com;
pagespeed Domain                             connect.facebook.com;
pagespeed Domain                             assets.pinterest.com;
pagespeed Domain                             *.twitter.com;
pagespeed Domain                             *.google-analytics.com;
pagespeed MapOriginDomain                   "https://localhost" "https://www.mydomain.com";
pagespeed MapRewriteDomain                  https://localhost/pageSpeed/printerest https://assets.pinterest.com;
pagespeed MapRewriteDomain                   https://localhost/pageSpeed/facebook https://connect.facebook.net;

#pagespeed MapRewriteDomain c0.wp.com https://www.mydomain.com;
#pagespeed MapRewriteDomain i1.wp.com https://www.mydomain.com;
#pagespeed MapRewriteDomain i0.wp.com https://www.mydomain.com;
#pagespeed MapRewriteDomain i2.wp.com https://www.mydomain.com;

pagespeed MapProxyDomain https://localhost/pageSpeed/printerest https://assets.pinterest.com;
pagespeed MapProxyDomain https://localhost/pageSpeed/facebook https://connect.facebook.net;
#pagespeed MapProxyDomain localhost/PageSpeed/twitter https://platform.twitter.com; 
#pagespeed MapProxyDomain localhost/PageSpeed/ganalytics https://www.google-analytics.com;
Lofesa commented 4 years ago

Hi @utags Perhaps not related but some of your directives are wrong.

pagespeed SslCertDirectory
pagespeed SslCertFile

These directives must be set NOT to your server certificates but to client ones, I will say these directives must be set to The default directory for Debian-based systems is /etc/ssl/certs, and there is no certificate file setting. On CentOS-based systems, the default directory is /etc/pki/tls/certs and default file is /etc/pki/tls/cert.pem. as stated here

You have configured pagespeed LoadFromFileMatch but I think pagespeed LoadFromFile is better.

pagespeed ProcessScriptVariables on;
  pagespeed LoadFromFile "http://$host/" "$document_root";

And for the proxy domain try to put a endig slash and enclose it on quotation marks: pagespeed MapProxyDomain "https://localhost/pageSpeed/printerest/" "https://assets.pinterest.com/";

Chathu07 commented 4 years ago

Hi @Lofesa

I have modified the configuration file as you mentioned, but still it shows same error.

root@server:# nginx -t nginx: [emerg] "pagespeed" directive "MapProxyDomain "https://localhost/pagespeed/facebook"" not recognized or too many arguments in /var/www/mydomain.com/pagespeed-nginx.conf:27 nginx: configuration file /etc/nginx/nginx.conf test failed root@server:#

Lofesa commented 4 years ago

Hi @utags As far as I can see you have enabled 2 of these directives, for facebook and for pinterest. The pinterest one don´t have error? Have you copy-pasted the directive from somewhere? maybe it have a strange character. In other hand in all test files I see that the directive is splited in 2 lines, but I think is not related.

pagespeed MapProxyDomain secondary.example.com/gstatic_images
                             http://www.gstatic.com/psa/static;

This error come from this and say that the name of the directive is not recognized......

Chathu07 commented 4 years ago

Dear @Lofesa ,

As you mentioned there's some strange (invisible) charecter in my configuration file. After copying pinterest MapProxyDomain line and modified to FB and twitter relevent URL's it worked. Although still my pages I can see that, twitter and FB links (After purge FastCGI cache). Could you please tell me why is that proxy filter not working?

Lofesa commented 4 years ago

Hi @utags Sorry, but my english is so bad. Do you mean that in you pages have fb and tw links? you have these pagespeed MapRewriteDomain https://localhost/pageSpeed/printerest https://assets.pinterest.com; pagespeed MapRewriteDomain https://localhost/pageSpeed/facebook https://connect.facebook.net; so allmost fb and pinterest must have their url changed, but not tw unless yo have added. Test if you have files in the proxied directories (have these directories created?), if yes the filter is working.

Perhaps not related but you have this in config file:

pagespeed Domain                             *.wp.com;
pagespeed Domain                             connect.facebook.com;
pagespeed Domain                             assets.pinterest.com;
pagespeed Domain                             *.twitter.com;
pagespeed Domain                             *.google-analytics.com;

These are not correct. Whit these directive, the specified domains MUST run pagespeed and as far as I know none of these do. You need this for your own domain:

pagespeed Domain https*://*.mydomain.com*

Cause, I suppose, you are running pagespeed in localhost and by default pagespeed only rewrites resources from the server where it runs.

EDIT: Sure you will get a url in the html code like https://localhost/pageSpeed/facebook ?

Chathu07 commented 4 years ago

Dear @Lofesa

Thank you for your detailed reply. When I navigate to pageSpeed/printerest and pageSpeed/facebook directories, they are empty. Still my website source has original FB and twitter links (//connect.facebook.net/en_US/all.js) (https://platform.twitter.com/widgets.js).

Lofesa commented 4 years ago

Hi @utags Whats happens when you make a curl to the localhost himself? If no files in the proxied folders, the filter is not working. Try to view the debug messages when you add /?PageSpeedFilters=+debug to a url. This inject debug messages in the html code. Can you share a url to test?