apache / incubator-pagespeed-ngx

Automatic PageSpeed optimization module for Nginx
http://ngxpagespeed.com/
Apache License 2.0
4.37k stars 365 forks source link

Pagespeed not combining CSS or JS and not rewriting some images URL #1277

Open journeytosilius opened 8 years ago

journeytosilius commented 8 years ago

Pagespeed is not rewriting most of the content to the CDN, specially some images and also not combining CSS or JS files.

On the source with debug on I get this :

<link rel=stylesheet href="https://a.chinaboundltd.com/wp-content/plugins/formcraft3/assets/css/form.min.css?ver=3.2.18"><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/plugins/formcraft3/assets/css/form.min.css?ver=3.2.18--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/plugins/formcraft3/assets/css/form.min.css?ver=3.2.18--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/plugins/formcraft3/assets/css/form.min.css?ver=3.2.18--><link rel=stylesheet href="https://a.chinaboundltd.com/wp-content/plugins/js_composer/assets/css/js_composer.min.css?ver=4.11.2.1"><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/plugins/js_composer/assets/css/js_composer.min.css?ver=4.11.2.1--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/plugins/js_composer/assets/css/js_composer.min.css?ver=4.11.2.1--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/plugins/js_composer/assets/css/js_composer.min.css?ver=4.11.2.1--><link rel=stylesheet href="https://a.chinaboundltd.com/wp-content/themes/modo/assets/css/bootstrap.css"><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/themes/modo/assets/css/bootstrap.css--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/themes/modo/assets/css/bootstrap.css--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/themes/modo/assets/css/bootstrap.css--><link rel=stylesheet href="https://a.chinaboundltd.com/wp-content/themes/modo/assets/css/modo.css?ver=1.0"><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/themes/modo/assets/css/modo.css?ver=1.0--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/themes/modo/assets/css/modo.css?ver=1.0--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/themes/modo/assets/css/modo.css?ver=1.0--><link rel=stylesheet href="https://a.chinaboundltd.com/wp-content/themes/modo/assets/css/skins/gray.css"><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/themes/modo/assets/css/skins/gray.css--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/themes/modo/assets/css/skins/gray.css--><!--4xx status code, preventing rewriting of https://chinaboundltd.com/wp-content/themes/modo/assets/css/skins/gray.css--><style>

Nginx logs : 2016/09/19 06:43:39 [error] 16537#0: [ngx_pagespeed 1.11.33.2-0] https://chinaboundltd.com/wp-content/uploads/2016/06/cbweb24.jpg:0:serf_context_run error status=20014 (Internal error)

Pagespeed configuration :

pagespeed on;

# Needs to exist and be writable by nginx.  Use tmpfs for best performance.
pagespeed FileCachePath /tmp/pagespeed/chinabound;

location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
  add_header "" "";
}

pagespeed Disallow */admin/*;
pagespeed Disallow */wp-admin/*;
pagespeed Disallow */tinymce/*;
pagespeed Disallow */mysql/*;
pagespeed Disallow */my-account/*;
pagespeed Disallow */cart/*;
pagespeed Disallow */checkout/*;
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
pagespeed FetchHttps enable;
pagespeed LoadFromFile "https://127.0.0.1" "/var/www/chinabound.com/wordpress/";
#pagespeed MapOriginDomain "http://127.0.0.1" "https://chinaboundltd.com";
#pagespeed LoadFromFile "https://127.0.0.1:8081" "/var/www/elsitar.com/wordpress/";
#pagespeed LoadFromFile "http://127.0.0.1:8081" "/var/www/elsitar.com/wordpress/";
#pagespeed LoadFromFile "http://elsitar.com" "/var/www/elsitar.com/wordpress/";
pagespeed RespectXForwardedProto on;
pagespeed ModifyCachingHeaders on;
#pagespeed LoadFromFile "https://chinaboundltd.com" "/var/www/chinabound.com/wordpress/";
#Purge cache 

pagespeed EnableCachePurge on;

#HTTPS certificates

pagespeed SslCertDirectory /etc/letsencrypt/live/chinaboundltd.com;
pagespeed SslCertFile fullchain.pem;

#Analytics

pagespeed RewriteLevel CoreFilters;

#pagespeed RewriteLevel PassThrough;

pagespeed EnableFilters collapse_whitespace;

pagespeed EnableFilters remove_comments;

pagespeed EnableFilters remove_quotes;

pagespeed EnableFilters trim_urls;

pagespeed EnableFilters prioritize_critical_css;

pagespeed EnableFilters move_css_to_head;

pagespeed EnableFilters flatten_css_imports;

pagespeed EnableFilters move_css_above_scripts;

pagespeed EnableFilters outline_javascript;

pagespeed EnableFilters outline_css;

#pagespeed EnableFilters defer_javascript;

pagespeed EnableFilters insert_dns_prefetch;

pagespeed EnableFilters combine_css;

pagespeed EnableFilters combine_javascript;

pagespeed EnableFilters combine_heads;

pagespeed EnableFilters inline_javascript;

pagespeed EnableFilters inline_css;

pagespeed EnableFilters elide_attributes;

pagespeed EnableFilters convert_meta_tags;

pagespeed EnableFilters lazyload_images;

pagespeed LazyloadImagesAfterOnload on;

pagespeed EnableFilters move_css_to_head;

pagespeed EnableFilters rewrite_images;

pagespeed EnableFilters recompress_images;

pagespeed EnableFilters convert_jpeg_to_progressive;

pagespeed EnableFilters recompress_jpeg;

pagespeed EnableFilters recompress_png;

pagespeed EnableFilters strip_image_color_profile;

pagespeed EnableFilters jpeg_subsampling;

pagespeed EnableFilters convert_png_to_jpeg;

pagespeed DisableFilters resize_images;

pagespeed EnableFilters inline_import_to_link;

pagespeed EnableFilters rewrite_style_attributes;

pagespeed EnableFilters rewrite_javascript_external;

pagespeed EnableFilters convert_jpeg_to_webp;

pagespeed EnableFilters extend_cache;

pagespeed EnableFilters insert_img_dimensions;

pagespeed EnableFilters resize_mobile_images;

pagespeed EnableFilters sprite_images;

pagespeed EnableFilters canonicalize_javascript_libraries;

pagespeed EnableFilters rewrite_css,sprite_images;

pagespeed DomainRewriteHyperlinks on;

pagespeed EnableFilters rewrite_style_attributes;

pagespeed EnableFilters rewrite_style_attributes_with_url;

pagespeed EnableFilters debug;

pagespeed AvoidRenamingIntrospectiveJavascript off;

#pagespeed EnableFilters insert_ga;
#pagespeed AnalyticsID UA-7174124-18;

#pagespeed DownstreamCachePurgeLocationPrefix http://127.0.0.1:8080;
pagespeed EnableFilters rewrite_domains;
#pagespeed DownstreamCacheRebeaconingKey "yoursecretkey";
pagespeed ShardDomain   https://chinaboundltd.com https://a.chinaboundltd.com;

pagespeed Statistics on;
pagespeed StatisticsLogging on;
pagespeed LogDir /var/log/pagespeed;
pagespeed AdminPath /pagespeed_admin;

pagespeed StatisticsLoggingIntervalMs 60000;
pagespeed StatisticsLoggingMaxFileSizeKb 1024;

NOTE : Sometimes it does rewrite the JS partially ( not the CSS though ) and combines it. It also sometimes rewrites more URL's to the CDN, as shown on this result :

cdn

jeffkaufman commented 8 years ago

This configuration looks suspicious:

pagespeed SslCertDirectory /etc/letsencrypt/live/chinaboundltd.com;
pagespeed SslCertFile fullchain.pem;

What are you trying to do with those two lines? Do you need them?

journeytosilius commented 8 years ago

Hi Jeff, ok I have removed it and now seems that pagespeed is doing more work, like transforming images to webp and combining the CSS. But the JS is still not being combined and only a few files are being rewritten to the CDN. Note that I have changed from sharding domains to :

pagespeed EnableFilters rewrite_domains;
pagespeed MapRewriteDomain https://a.chinaboundltd.com https://chinaboundltd.com;

And it does the same as it did before. Only some URL's are being rewritten.

Also, strangely my first byte time has ramped up. Any thoughts please ? Thank you.

oschaaf commented 8 years ago

It seems your javascript files are injected via javascript. ngx_pagespeed will not be able to combine them because it is not able to parse them out of the script that injects them.

I do not see any domain rewriting occurring at all at the moment. Do you still have that configured? If so, are you sure that the webserver receives a correct X-Forwarded-Proto header?

journeytosilius commented 8 years ago

Hi Otto, sorry I was making some tests on the configuration. If you visit the site now you will be able to see that only 46% of the assets are being rewritten to the CDN. Where should I check for the header sending ?

oschaaf commented 8 years ago

Hopefully you can set up forwarding of the header at your cdn. To verify nginx is receiving it, you need debug level logging so you can check the incoming request headers from the CDN: http://nginx.org/en/docs/debugging_log.html