: Restrict mod_pagespeed to specific domains on a server If a server hosts the following domains:- http://exampleA.com http://exampleB.com http://exampleC.com How is it possible to enable mod_pagespeed
If a server hosts the following domains:-
exampleA.com http://exampleB.com exampleC.com
How is it possible to enable mod_pagespeed for only domains exampleA.com and exampleC.com but not exampleB.com?
I have read up on the documentation for domains but not quite sure I can fathom out if this possible to achieve...
I have tried inserting the following into pagespeed.conf and restarting Apache but mod_pagespeed is still applying to all domains...
ModPagespeedDomain exampleA.com ModPagespeedDomain exampleC.com
More posts by @Angela700
2 Comments
Sorted by latest first Latest Oldest Best
If you can use .htaccess files you can simply set ModPagespeed off in the httpd.conf and then do this in the root .htaccess for any domain you want it enabled on:
<IfModule pagespeed_module>
ModPagespeed on
</IfModule>
If you are using Apache 2.4+ you can even use the <If> directive for cases where the same .htaccess file is used for multiple domains, or for example if you have the .htaccess in a Git repository and you use the same one for the production and development sites but want ModPagespeed on only for the production site:
<IfModule pagespeed_module>
<If "req('Host') == 'www.example.com'">
ModPagespeed on
</If>
<Else>
ModPagespeed off
</Else>
</IfModule>
After a little digging and playing around with this, I've managed to figure it out and now have a working scenario for mod_pagespeed to only work on specific domains (vhosts) on the same server.
My configuration is based on a CentOs 6 build Apache 2 that runs Parallels Plesk Panel.
Create a separate pagespeed conf file and store it in a location that won't be a) automatically overwrote or b) automatically loaded (i.e in the existing conf or conf.d directories). In my instance, I created /etc/httpd/myconf and named the file vhosts-pagespeed.conf.
This configuration file will contain themod_pagespeed configuration you wish specific domains to use (you can create as many of these as you like). For example, mine is like:-
#https ://developers.google.com/speed/pagespeed/module/configuration#virtual-hosts
<IfModule pagespeed_module>
ModPagespeed on
AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html
ModPagespeedFileCachePath "/var/cache/mod_pagespeed/"
ModPagespeedFileCacheInodeLimit 500000
ModPagespeedAvoidRenamingIntrospectiveJavascript on
ModPagespeedLibrary 105527 ltVVzzYxo0 //ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js
ModPagespeedLibrary 92501 J8KF47pYOq //ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js
ModPagespeedLibrary 141547 GKjMUuF4PK //ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js
ModPagespeedLibrary 43 1o978_K0_L www.modpagespeed.com/rewrite_javascript.js
ModPagespeedEnableFilters extend_cache
ModPagespeedEnableFilters rewrite_javascript
ModPagespeedEnableFilters rewrite_css
ModPagespeedEnableFilters combine_javascript
ModPagespeedEnableFilters combine_css
ModPagespeedEnableFilters inline_javascript
ModPagespeedEnableFilters inline_css
ModPagespeedEnableFilters insert_img_dimensions
ModPagespeedEnableFilters move_css_to_head
ModPagespeedEnableFilters lazyload_images
ModPagespeedEnableFilters rewrite_images
ModPagespeedEnableFilters outline_css
ModPagespeedEnableFilters flatten_css_imports
ModPagespeedEnableFilters inline_import_to_link
ModPagespeedEnableFilters local_storage_cache
ModPagespeedEnableFilters collapse_whitespace
ModPagespeedEnableFilters elide_attributes
ModPagespeedEnableFilters remove_comments
ModPagespeedDisableFilters rewrite_javascript,combine_javascript
ModPagespeedModifyCachingHeaders off
ModPagespeedDomain *
<Location /mod_pagespeed_beacon>
SetHandler mod_pagespeed_beacon
</Location>
<Location /mod_pagespeed_statistics>
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
SetHandler mod_pagespeed_statistics
</Location>
<Location /mod_pagespeed_console>
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
SetHandler mod_pagespeed_console
</Location>
<Location /mod_pagespeed_message>
Allow from localhost
Allow from 127.0.0.1
SetHandler mod_pagespeed_message
</Location>
<Location /mod_pagespeed_referer_statistics>
Allow from localhost
Allow from 127.0.0.1
SetHandler mod_pagespeed_referer_statistics
</Location>
</IfModule>
You'll then need to disable the global mod_pagespeed and only include the vhost specific pagespeed config on those domains which you wish to enable mod_pagespeed.
Navigate to /var/www/vhosts/domain.com/conf and create the file vhost.conf with the include (this is all this file needs to contain):-
Include /etc/httpd/myconf/vhosts-pagespeed.conf
Disable global /etc/httpd/conf.d/pagespeed.conf by modifying like so:-
ModPagespeed off
Then restart the server:-
service httpd restart
Now check that mod_pagespeed is enabled on the domain.com that you extended the vhost to include the custom pagespeed conf.
If that doesn't work, you may find you need to reconfigure the vhost for domain.com with something like:-
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=domain.com
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.