markdown Pagespeed模块(Apache)指令

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Pagespeed模块(Apache)指令相关的知识,希望对你有一定的参考价值。

# Using Google Pagespeed module (Apache)

## Install

Follow initial install instructions [here](https://www.digitalocean.com/community/tutorials/how-to-get-started-with-mod_pagespeed-with-apache-on-an-ubuntu-and-debian-cloud-server)

## Recommended additional modules

Add the following to the bottom (but inside the `<IfModule />` block) of `/etc/apache2/mods-available/pagespeed.conf`

```TEXT
ModPagespeedRewriteLevel OptimizeForBandwidth
ModPagespeedDomain http://yourdomainhere.co.uk
ModPagespeedEnableFilters responsive_images,resize_images,lazyload_images,convert_jpeg_to_progressive
ModPagespeedEnableFilters combine_css,prioritize_critical_css,rewrite_css,fallback_rewrite_css_urls
ModPagespeedEnableFilters canonicalize_javascript_libraries,rewrite_javascript,defer_javascript
ModPagespeedEnableFilters collapse_whitespace,extend_cache,trim_urls
ModPagespeedForceCaching on
ModPagespeedEnableCachePurge on
```

`ModPagespeedRewriteLevel` sets the general configuration level for the Pagespeed Module. `CoreFilters` is the default value
however, more recently the `OptimizeForBandwidth` setting has proven as effective with less issues across website. More 
information can be found [here](https://modpagespeed.com/doc/optimize-for-bandwidth)

`ModPagespeedDomain` sets the domain to authorise file changes against i.e. when minifying or compressing images etc this 
must match the domain serving this content. Multiple `ModPagespeedDomain` can be defined for multiple domains if your server 
runs multiple sites.

`ModPagespeedEnableFilters` defines and activates addition filters for content types to be passed through in addition to a 
core set of filters defined [here](https://developers.google.com/speed/pagespeed/module/config_filters#level). Please refer to 
the [reference section](https://developers.google.com/speed/pagespeed/module/filter-image-responsive) for details about each of
the filters above. (Note, you can comma separate multiple filters and break onto multiple lines, redeclaring 
`ModPagespeedEnableFilters` each time, for improved readibility).

`ModPagespeedForceCaching` enforces cache control for resources, for more information see 
[https://developers.google.com/speed/pagespeed/module/filter-cache-extend](https://developers.google.com/speed/pagespeed/module/filter-cache-extend)

`ModPagespeedEnableCachePurge` is required (set to on) in order to allow for purge requests from the admin screens 
(defaults to `/pagespeed_admin` & `/pagespeed_global_admin`).

## Using with WordPress sites

The install instructions and configurations will work out of the box for WordPress sites, however, in order to access the admin
pages, an exception must be added to your `.htaccess` file, see the example below:

```
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !pagespeed
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
```

Note: The line `RewriteCond %{REQUEST_URI} !pagespeed` - this ensures WordPress doesn't try and looking for a page with a slug containing `pagespeed`, however this will only be preserved if your `.htaccess` file is `readonly` as WordPress will refresh this when updating its permalinks. To prevent this you can set the `RewriteEngine` to `off` when attempting to access the admin pages within the `pagespeed.conf` file:

```
<Location /pagespeed_admin>
    <IfModule mod_rewrite.c>
        RewriteEngine Off
    </IfModule>
</Location>
```

It's also worth being aware that by default the pagespeed module will be applied across the whole of your WordPress install, including the admin area which can lead to some issues with internal ajax events. To remedy this, add the following to the buttom of the `pagespeed.conf` file:

```
<Location /wp-admin/>
    ModPagespeed Off
</Location>
```

This is disable the pagespeed module for any and all pages (and files) under the `/wp-admin` directory. Once this has been edited, ensure you run `service apache2 restart` for the changes to take affect.

## Using on a Cloudflare site with SSL

I've been using Cloudflare's free SSL alongside it's other services for a couple of WordPress sites. You can use the pagespeed module with this setup, however, you need to take into account that when using Cloudflare on your site, the visitor's IP address isn't logged, rather the Cloudflare service IP address is passed instead. This will lead to a `403` (Forbbiden) message being returned when attempting to access the `/pagespeed_admin` pages.

To fix this issue, simply follow the instructions [here](https://support.cloudflare.com/hc/en-us/articles/203656534-How-do-I-restore-original-visitor-IP-with-Apache-2-4-) which will ensure that the visitor IP is passed through correctly from Cloudflare to the server (Apache) and validates correctly to allow access to the admin pages. 

以上是关于markdown Pagespeed模块(Apache)指令的主要内容,如果未能解决你的问题,请参考以下文章

Http2需要PageSpeed模块吗?

PageSpeed 模块弄乱了图像的比例

Nginx开启ngx_pagespeed模块

nginx加速模块ngx_pagespeed

删除 Nginx 并使用 Pagespeed 模块安装 Nginx

如何配置 gulpjs 使得 ngrok 模块可用于为 pagespeed 洞察插件提供 url?