nginx caching and smart files processing

56 views
Skip to first unread message

Ungov

unread,
Feb 21, 2022, 3:24:20 AM2/21/22
to mod-pagespeed-discuss
Hello,
When using mod pagespeed with nginx in proxy mode, should I enable any of the 3 below options?

nginx s.png

Longinos

unread,
Feb 21, 2022, 3:49:28 AM2/21/22
to mod-pagespeed-discuss
Hi
No, is not needed for pagespeed.
Having say this, serving statics files with nginx is more efficient than with apache.
But depending on how this is configured maybe pagespeed config need to be changed.

Ungov

unread,
Feb 21, 2022, 5:47:41 PM2/21/22
to mod-pagespeed-discuss
Hello,

I know it is not needed, but is it recommended? It seems like enabling those 3 options would help performance. I'm just wondering if there is any incompatibility with pagespeed or if I will run into issues

What part of pagespeed config will need to be changed?

Here is my config for reference



KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 100

ModPagespeed On

# SSL
ModPagespeedSslCertDirectory "/etc/pki/tls/certs"
ModPagespeedSslCertFile "/etc/pki/tls/cert.pem"

# fix error 4xx & uncacheable
ModPagespeedLoadFromFile "https://www.******.com/" \
"/var/www/vhosts/******.com/public_html/"
ModPagespeedMapRewriteDomain  "https://www.******.com" "http://localhost:7080"
# ModPagespeedMapOriginDomain "http://localhost" "https://www.******.com"

# Performance (fix deadline_exceeded)
ModPagespeedRateLimitBackgroundFetches off
#ModPagespeedImageMaxRewritesAtOnce 5000
ModPagespeedLRUCacheKbPerProcess   1024
ModPagespeedLRUCacheByteLimit      16384

# Server-Side Caching
ModPagespeedFileCachePath            "/var/cache/mod_pagespeed/"
ModPagespeedFileCacheSizeKb          5000000
ModPagespeedFileCacheCleanIntervalMs 3600000
ModPagespeedFileCacheInodeLimit      5000000
#ModPagespeedLoadFromFileRuleMatch disallow .*
#ModPagespeedLoadFromFileRuleMatch \.(js|css|jpg|jpeg|png|pdf|gif)$
ModPagespeedLoadFromFileCacheTtlMs 2419200000
ModPagespeedDownstreamCachePurgeLocationPrefix http://localhost:8443
ModPagespeedDownstreamCacheRebeaconingKey "5435543645"

# authorize all domains
ModPagespeedDomain *
ModPagespeedEnableFilters rewrite_domains

# URL's
ModPagespeedImagePreserveURLs on
ModPagespeedEnableFilters in_place_optimize_for_browser
ModPagespeedInPlaceResourceOptimization on
ModPagespeedSupportNoScriptEnabled false
# ModPagespeedDisableRewriteOnNoTransform off

# CSS Optimizations
ModPagespeedEnableFilters rewrite_css
ModPagespeedEnableFilters rewrite_style_attributes
ModPagespeedEnableFilters combine_css
ModPagespeedEnableFilters prioritize_critical_css
ModPagespeedEnableFilters outline_css
ModPagespeedEnableFilters inline_import_to_link
ModPagespeedEnableFilters inline_css
#ModPagespeedEnableFilters move_css_above_scripts
#ModPagespeedEnableFilters move_css_to_head

# IMAGES Optimizations
ModPagespeedEnableFilters recompress_images
ModPagespeedEnableFilters convert_png_to_jpeg
ModPagespeedEnableFilters convert_jpeg_to_progressive
ModPagespeedEnableFilters convert_jpeg_to_webp
ModPagespeedEnableFilters convert_to_webp_lossless
ModPagespeedEnableFilters recompress_webp
ModPagespeedEnableFilters lazyload_images
ModPagespeedEnableFilters resize_images
ModPagespeedEnableFilters resize_rendered_image_dimensions
ModPagespeedEnableFilters inline_images
ModPagespeedEnableFilters inline_preview_images
ModPagespeedEnableFilters strip_image_meta_data
ModPagespeedEnableFilters insert_image_dimensions

# Image Compression Quality
ModPagespeedImageRecompressionQuality 85
ModPagespeedJpegRecompressionQuality 85
ModPagespeedJpegRecompressionQualityForSmallScreens 70
ModPagespeedWebpRecompressionQuality 80
ModPagespeedWebpRecompressionQualityForSmallScreens 70

# HTML Optimizations
ModPagespeedEnableFilters collapse_whitespace
ModPagespeedEnableFilters remove_comments
ModPagespeedLowercaseHtmlNames on

# JAVASCRIPT Optimizations
ModPagespeedEnableFilters rewrite_javascript
ModPagespeedEnableFilters defer_javascript
ModPagespeedEnableFilters outline_javascript
#ModPagespeedEnableFilters combine_javascript
ModPagespeedDisallow "*/ajax_shop.js"
ModPagespeedDisallow "*/ajax_basketid.js"
ModPagespeedDisallow "*/ajax_get_stock_state.js"
ModPagespeedDisallow "*/basket_size.js"
ModPagespeedDisallow "*/basket_size_ajax.js"
ModPagespeedDisallow "*/basket_api_get_basketitems.js"
ModPagespeedDisallow "*/basket_api.js"
ModPagespeedDisallow "*/basket_product.js"
ModPagespeedDisallow "*/basket_hover.js"

# Third Party Libraries
ModPagespeedEnableFilters canonicalize_javascript_libraries
#ModPagespeedEnableFilters make_google_analytics_async

# Leverage Browser Caching
ModPagespeedEnableFilters extend_cache
ModPagespeedModifyCachingHeaders off
ModPagespeedEnableFilters hint_preload_subresources

AddOutputFilterByType DEFLATE text/plain text/html text/xml;
AddOutputFilterByType DEFLATE text/css text/javascript;
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml;
AddOutputFilterByType DEFLATE application/rss+xml;
AddOutputFilterByType DEFLATE application/javascript application/x-javascript

<IfModule mod_expires.c>
        ExpiresActive On
        FileETag None
        ExpiresDefault "access plus 14 days"
        ExpiresByType image/jpg "access plus 1 year"
        ExpiresByType image/gif "access plus 1 year"
        ExpiresByType image/jpeg "access plus 1 year"
        ExpiresByType image/png "access plus 1 year"
        ExpiresByType text/css "access plus 1 year"
        ExpiresByType application/pdf "access plus 1 year"
        ExpiresByType text/javascript "access plus 1 year"
        ExpiresByType text/x-javascript "access plus 1 year"
        ExpiresByType application/javascript "access plus 1 year"
        ExpiresByType application/x-shockwave-flash "access plus 1 year"
        ExpiresByType text/css "now plus 1 month"
        ExpiresByType image/ico "access plus 1 year"
        ExpiresByType image/x-icon "access plus 1 year"
        ExpiresByType text/html "access plus 1 days"
</IfModule>

Longinos

unread,
Feb 21, 2022, 8:47:25 PM2/21/22
to mod-pagespeed-discuss
Hi
Despite of the issue related to the 1st email, you have
ModPagespeedDomain *
This a wrong config option.

These directive must be used to auth domains you know are running pagespeed.
By default pagespeed rewrites resources from the http version of the domain from where the html is served, so if you use https you must set
ModPagespeedDomain https://mydomain.com
or if you use any subdomain
ModPagespeedDomain https://*.domain.com

About the issue:
These config come from apache server. If you sett the config for serving assets from nginx
you need to config pagespeed to run in nginx.
Donwload the nginx version of pagespeed, compile it with nginx and configure it.

Longinos

unread,
Feb 21, 2022, 9:05:00 PM2/21/22
to mod-pagespeed-discuss
Hi again
In these config you have:
ModPagespeedEnableFilters outline_css
and
ModPagespeedEnableFilters inline_css

What you need, all the css inlined or all the css outlined?
Anyway, these filter (and the same for javascript) have a default size of 2048Kb if I remember.
What this mean?
For the inline option, any file grether than 2048Kb CAN´T be inlined
https://www.modpagespeed.com/doc/filter-css-inline

Ungov

unread,
Feb 21, 2022, 9:57:07 PM2/21/22
to mod-pagespeed-discuss
Thanks for checking my config and reporting the issue with ModPagespeedDomain
I have a second domain also running pagespeed, and the second domain embeds some images hosted on the first domain. So if I understand correctly I should have both domains in ModPagespeedDomain?

I can't use outline_css AND inline_css at the same time? I thought it would take very small .css files and merge them into a <style></style> in the page's body, while outline_css would take all of the small inlined CSS in style="" attribute and merge it into an external CSS file. I guess I should disable inline_css and keep only outline_css then, as I have a lot of inline CSS everywhere on the website

As for the other questions, I just realized migrating to nginx version of pagespeed would be too much work, as it already took me a while to figure out how to configure it with Apache. Can I still enable the option "serve static files by nginx" if I keep the other 2 options disabled?
I am just worried about the warning "turn this off only for troubleshooting" (about smart file processing). Does this mean that disabling this option significantly reduces the performance?

Longinos

unread,
Feb 22, 2022, 5:09:05 AM2/22/22
to mod-pagespeed-discuss
Hi
Yes, if html from subdomain2.mydomain.com includes url´s from subdomain1.mydomain.com
then you need to auth subdomain1 in subdomain2.
How pagespeed rewrite works?:
Pgespeed rewrites resources in the html code, with auth subdomain1 in subdomain2 you permit that pagespeed rewrites a url https://subdomain1.mudomain.com/whatever-path/image.jpg present in the subdomain2 html to some like https://subdomain1.mydomain.com/whatsever-path/ximage.jpg.ic.pagespeed.HASH.webp and then send this rewrited url to subdomain1.

Yes, you can merge inline and outline, but for me don´t make much sense inline external css and outline otherwise inlined css.
But no, it don´t merge only put a <style></style> for each inlined file.
if you don´t set size, only files below 2024 bytes are inlined.
To change it to a great value you must use "ModPagespeedCssInlineMaxBytes bytes"

For outline there is a reverse function: only is outlined these css greather than some value:, to change these default valur:
"ModPagespeedCssOutlineMinBytes bytes"

Same for inline/outline javascript.

Combne css is only available via external file, created and stored in pagespeed cache.
ModPagespeedEnableFilters combine_css
ModPagespeedMaxCombinedCssBytes MaxBytes
Reply all
Reply to author
Forward
0 new messages