Skip to content

Commit

Permalink
Add support for mod_pagespeed
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfens committed Mar 6, 2014
1 parent 64fb41f commit 7d84d59
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 0 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [Class: apache::default_mods](#class-apachedefault_mods)
* [Defined Type: apache::mod](#defined-type-apachemod)
* [Classes: apache::mod::*](#classes-apachemodname)
* [Class: apache::mod::pagespeed](#class-apachemodpagespeed)
* [Class: apache::mod::ssl](#class-apachemodssl)
* [Class: apache::mod::wsgi](#class-apachemodwsgi)
* [Defined Type: apache::vhost](#defined-type-apachevhost)
Expand Down Expand Up @@ -442,6 +443,7 @@ There are many `apache::mod::[name]` classes within this module that can be decl
* `mime_magic`*
* `negotiation`
* `nss`*
* `pagespeed` (see [`apache::mod::pagespeed`](#class-apachemodpagespeed) below)
* `passenger`*
* `perl`
* `peruser`
Expand Down Expand Up @@ -470,6 +472,57 @@ Modules noted with a * indicate that the module has settings and, thus, a templa

The modules mentioned above, and other Apache modules that have templates, will cause template files to be dropped along with the mod install and the module will not work without the template. Any module without a template will install the package but drop no files.

####Class: `apache::mod::pagespeed`

Installs and manages mod_pagespeed, which is a Google module that rewrites web pages to reduce latency and bandwidth.

This module does *not* manage the software repositories needed to automatically install the
mod-pagespeed-stable package. The module does however require that the package be installed,
or be installable using the system's default package provider. You should ensure that this
pre-requisite is met or declaring `apache::mod::pagespeed` will cause the puppet run to fail.

These are the defaults:

```puppet
class { 'apache::mod::pagespeed':
inherit_vhost_config => 'on',
filter_xhtml => false,
cache_path => '/var/cache/mod_pagespeed/',
log_dir => '/var/log/pagespeed',
memache_servers => [],
rewrite_level => 'CoreFilters',
disable_filters => [],
enable_filters => [],
forbid_filters => [],
rewrite_deadline_per_flush_ms => 10,
additional_domains => undef,
file_cache_size_kb => 102400,
file_cache_clean_interval_ms => 3600000,
lru_cache_per_process => 1024,
lru_cache_byte_limit => 16384,
css_flatten_max_bytes => 2048,
css_inline_max_bytes => 2048,
css_image_inline_max_bytes => 2048,
image_inline_max_bytes => 2048,
js_inline_max_bytes => 2048,
css_outline_min_bytes => 3000,
js_outline_min_bytes => 3000,
inode_limit => 500000,
image_max_rewrites_at_once => 8,
num_rewrite_threads => 4,
num_expensive_rewrite_threads => 4,
collect_statistics => 'on',
statistics_logging => 'on',
allow_view_stats => [],
allow_pagespeed_console => [],
allow_pagespeed_message => [],
message_buffer_size => 100000,
additional_configuration => { }
}
```

Full documentation for mod_pagespeed is available from [Google](http://modpagespeed.com).

####Class: `apache::mod::ssl`

Installs Apache SSL capabilities and uses the ssl.conf.erb template. These are the defaults:
Expand Down
48 changes: 48 additions & 0 deletions manifests/mod/pagespeed.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class apache::mod::pagespeed (
$inherit_vhost_config = 'on',
$filter_xhtml = false,
$cache_path = '/var/cache/mod_pagespeed/',
$log_dir = '/var/log/pagespeed',
$memache_servers = [],
$rewrite_level = 'CoreFilters',
$disable_filters = [],
$enable_filters = [],
$forbid_filters = [],
$rewrite_deadline_per_flush_ms = 10,
$additional_domains = undef,
$file_cache_size_kb = 102400,
$file_cache_clean_interval_ms = 3600000,
$lru_cache_per_process = 1024,
$lru_cache_byte_limit = 16384,
$css_flatten_max_bytes = 2048,
$css_inline_max_bytes = 2048,
$css_image_inline_max_bytes = 2048,
$image_inline_max_bytes = 2048,
$js_inline_max_bytes = 2048,
$css_outline_min_bytes = 3000,
$js_outline_min_bytes = 3000,
$inode_limit = 500000,
$image_max_rewrites_at_once = 8,
$num_rewrite_threads = 4,
$num_expensive_rewrite_threads = 4,
$collect_statistics = 'on',
$statistics_logging = 'on',
$allow_view_stats = [],
$allow_pagespeed_console = [],
$allow_pagespeed_message = [],
$message_buffer_size = 100000,
$additional_configuration = {},
){

apache::mod { 'pagespeed': }

file { 'pagespeed.conf':
ensure => file,
path => "${::apache::mod_dir}/pagespeed.conf",
content => template('apache/mod/pagespeed.conf.erb'),
require => Exec["mkdir ${::apache::mod_dir}"],
before => File[$::apache::mod_dir],
notify => Service['httpd'],
}

}
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
'authnz_ldap' => 'mod_authz_ldap',
'fastcgi' => 'mod_fastcgi',
'fcgid' => 'mod_fcgid',
'pagespeed' => 'mod-pagespeed-stable',
'passenger' => 'mod_passenger',
'perl' => 'mod_perl',
'php5' => $distrelease ? {
Expand Down Expand Up @@ -123,6 +124,7 @@
'fastcgi' => 'libapache2-mod-fastcgi',
'fcgid' => 'libapache2-mod-fcgid',
'nss' => 'libapache2-mod-nss',
'pagespeed' => 'mod-pagespeed-stable',
'passenger' => 'libapache2-mod-passenger',
'perl' => 'libapache2-mod-perl2',
'php5' => 'libapache2-mod-php5',
Expand Down
85 changes: 85 additions & 0 deletions spec/acceptance/mod_pagespeed_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
require 'spec_helper_acceptance'

describe 'apache::mod::pagespeed class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
case fact('osfamily')
when 'Debian'
vhost_dir = '/etc/apache2/sites-enabled'
mod_dir = '/etc/apache2/mods-available'
service_name = 'apache2'
when 'RedHat'
vhost_dir = '/etc/httpd/conf.d'
mod_dir = '/etc/httpd/conf.d'
service_name = 'httpd'
when 'FreeBSD'
vhost_dir = '/usr/local/etc/apache22/Vhosts'
mod_dir = '/usr/local/etc/apache22/Modules'
service_name = 'apache22'
end

context "default pagespeed config" do
it 'succeeds in puppeting pagespeed' do
pp= <<-EOS
if $::osfamily == 'Debian' {
class { 'apt': }
apt::source { 'mod-pagespeed':
key => '7FAC5991',
key_server => 'pgp.mit.edu',
location => 'http://dl.google.com/linux/mod-pagespeed/deb/',
release => 'stable',
repos => 'main',
include_src => false,
before => Class['apache'],
}
} elsif $::osfamily == 'RedHat' {
yumrepo { 'mod-pagespeed':
baseurl => 'http://dl.google.com/linux/mod-pagespeed/rpm/stable/x86_64',
enabled => 1,
gpgcheck => 1,
gpgkey => 'https://dl-ssl.google.com/linux/linux_signing_key.pub',
before => Class['apache'],
}
}
class { 'apache':
mpm_module => 'prefork',
}
class { 'apache::mod::pagespeed':
enable_filters => ['remove_comments'],
disable_filters => ['extend_cache'],
forbid_filters => ['rewrite_javascript'],
}
apache::vhost { 'pagespeed.example.com':
port => '80',
docroot => '/var/www/pagespeed',
}
host { 'pagespeed.example.com': ip => '127.0.0.1', }
file { '/var/www/pagespeed/index.html':
ensure => file,
content => "<html>\n<!-- comment -->\n<body>\n<p>Hello World!</p>\n</body>\n</html>",
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe service(service_name) do
it { should be_enabled }
it { should be_running }
end

describe file("#{mod_dir}/pagespeed.conf") do
it { should contain "AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html" }
it { should contain "ModPagespeedEnableFilters remove_comments" }
it { should contain "ModPagespeedDisableFilters extend_cache" }
it { should contain "ModPagespeedForbidFilters rewrite_javascript" }
end

it 'should answer to pagespeed.example.com and include <head/> and be stripped of comments by mod_pagespeed' do
shell("/usr/bin/curl pagespeed.example.com:80") do |r|
r.stdout.should =~ /<head\/>/
r.stdout.should_not =~ /<!-- comment -->/
r.exit_code.should == 0
end
end
end
end
32 changes: 32 additions & 0 deletions spec/classes/mod/pagespeed_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe 'apache::mod::pagespeed', :type => :class do
let :pre_condition do
'include apache'
end
context "on a Debian OS" do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
it { should contain_class("apache::params") }
it { should contain_apache__mod('pagespeed') }
it { should contain_package("mod-pagespeed-stable") }
it { should contain_file('pagespeed.conf') }
end

context "on a RedHat OS" do
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
it { should contain_class("apache::params") }
it { should contain_apache__mod('pagespeed') }
it { should contain_package("mod-pagespeed-stable") }
it { should contain_file('pagespeed.conf') }
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
if fact('osfamily') == 'RedHat'
on host, puppet('module','install','stahnma/epel'), { :acceptable_exit_codes => [0,1] }
end
# Required for manifest to make mod_pagespeed repository available
if fact('osfamily') == 'Debian'
on host, puppet('module','install','puppetlabs-apt'), { :acceptable_exit_codes => [0,1] }
end
on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module','install','puppetlabs-concat'), { :acceptable_exit_codes => [0,1] }
end
Expand Down
101 changes: 101 additions & 0 deletions templates/mod/pagespeed.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
ModPagespeed on

ModPagespeedInheritVHostConfig <%= @inherit_vhost_config %>
AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html
<% if @filter_xhtml -%>
AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER application/xhtml+xml
<% end -%>
ModPagespeedFileCachePath "<%= @cache_path %>"
ModPagespeedLogDir "<%= @log_dir %>"

<% @memache_servers.each do |server| -%>
ModPagespeedMemcachedServers <%= server -%>
<% end -%>

ModPagespeedRewriteLevel <%= @rewrite_level -%>

<% @disable_filters.each do |filter| -%>
ModPagespeedDisableFilters <%= filter -%>
<% end -%>

<% @enable_filters.each do |filter| -%>
ModPagespeedEnableFilters <%= filter -%>
<% end -%>

<% @forbid_filters.each do |filter| -%>
ModPagespeedForbidFilters <%= filter -%>
<% end -%>

ModPagespeedRewriteDeadlinePerFlushMs <%= @rewrite_deadline_per_flush_ms %>

<% if @additional_domains -%>
ModPagespeedDomain <%= @additional_domains -%>
<% end -%>

ModPagespeedFileCacheSizeKb <%= @file_cache_size_kb %>
ModPagespeedFileCacheCleanIntervalMs <%= @file_cache_clean_interval_ms %>
ModPagespeedLRUCacheKbPerProcess <%= @lru_cache_per_process %>
ModPagespeedLRUCacheByteLimit <%= @lru_cache_byte_limit %>
ModPagespeedCssFlattenMaxBytes <%= @css_flatten_max_bytes %>
ModPagespeedCssInlineMaxBytes <%= @css_inline_max_bytes %>
ModPagespeedCssImageInlineMaxBytes <%= @css_image_inline_max_bytes %>
ModPagespeedImageInlineMaxBytes <%= @image_inline_max_bytes %>
ModPagespeedJsInlineMaxBytes <%= @js_inline_max_bytes %>
ModPagespeedCssOutlineMinBytes <%= @css_outline_min_bytes %>
ModPagespeedJsOutlineMinBytes <%= @js_outline_min_bytes %>


ModPagespeedFileCacheInodeLimit <%= @inode_limit %>
ModPagespeedImageMaxRewritesAtOnce <%= @image_max_rewrites_at_once %>

ModPagespeedNumRewriteThreads <%= @num_rewrite_threads %>
ModPagespeedNumExpensiveRewriteThreads <%= @num_expensive_rewrite_threads %>

ModPagespeedStatistics <%= @collect_statistics %>

<Location /mod_pagespeed_statistics>
Order allow,deny
# You may insert other "Allow from" lines to add hosts you want to
# allow to look at generated statistics. Another possibility is
# to comment out the "Order" and "Allow" options from the config
# file, to allow any client that can reach your server to examine
# statistics. This might be appropriate in an experimental setup or
# if the Apache server is protected by a reverse proxy that will
# filter URLs in some fashion.
Allow from localhost
Allow from 127.0.0.1
Allow from ::1
<% @allow_view_stats.each do |host| -%>
Allow from <%= host %>
<% end -%>
SetHandler mod_pagespeed_statistics
</Location>

ModPagespeedStatisticsLogging <%= @statistics_logging %>
<Location /pagespeed_console>
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
Allow from ::1
<% @allow_pagespeed_console.each do |host| -%>
Allow from <%= host %>
<% end -%>
SetHandler pagespeed_console
</Location>

ModPagespeedMessageBufferSize <%= @message_buffer_size %>

<Location /mod_pagespeed_message>
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
Allow from ::1
<% @allow_pagespeed_message.each do |host| -%>
Allow from <%= host %>
<% end -%>
SetHandler mod_pagespeed_message
</Location>

<% @additional_configuration.each_pair do |key, value| -%>
<%= key %> <%= value %>
<% end -%>

0 comments on commit 7d84d59

Please sign in to comment.