1

I'd like to setup server to use pagespeed reverse proxy server with apache for several sites which cannot run pagespeed on their origin. It seems I should be able to create a VirtualHost for each site and use ModPagespeedMapProxyDomain to specify the origin server. I haven't been able to get this to work. Here's what I have so far.

  • http://origin.example.com/ is the web server for all dynamic and static content. It does not run pagespeed.
  • http://www.example.com/ will be the pagespeed server configured as a reverse proxy. No files are hosted here.

I've installed mod-pagespeed-stable-1.9.32.4-7251.x86_64 for CentOS and am using the default config from /etc/httpd/conf.d/pagespeed.conf except with CoreRules enabled—see my config.

I then added a VirtualHost directory:

<VirtualHost 111.222.333.444:80>
    ServerName www.example.com
    <IfModule pagespeed_module>
        ModPagespeed On
        ModPagespeedMapProxyDomain www.example.com origin.example.com
    </IfModule>
</VirtualHost>

Now any requests to http://www.example.com/ results in an empty page with a 403 Forbidden header:

[q@localhost ~] curl -I http://www.example.com/
HTTP/1.1 403 Forbidden
[…]

The request is logged to the global access_log, but there are no messages in error_log (does MPS have its own error log?). I am able to access http://www.example.com/pagespeed_global_admin but there is no indication there of errors.

If I remove the ModPagespeed* config and set up the vhost as a proxy using ProxyPassReverse / http://origin.example.com/, the site loads fine. However, of course, pagespeed doesn't take effect.

Can you see what I've done wrong? What is the recommended way to setup a pagespeed reverse proxy?

  • Did you ever figure this out? – Keith Dec 22 '15 at 4:40
1

Here is the configuration I found that fulfilled my requirements.

Indeed, use of mod_proxy is required, because mod_pagespeed does not have the ability to actually proxy requests. This VirtualHost config works to receive requests for www.example.com as a proxy for content served by another server at origin.example.com. Uncomment the ModPagespeedEnableFilters lines to enable specific PageSpeed features. You can view the PageSpeed admin at www.example.com/pagespeed_admin.

<VirtualHost 1.2.3.4:80>
    ServerName example.com
    ServerAlias www.example.com
    CustomLog /home/example/logs/access_log combined
    ErrorLog /home/example/logs/error_log
    <IfModule mod_proxy.c>
        ProxyPass /pagespeed_admin !
        ProxyPass /logs/ !
        ProxyPass / http://origin.example.com/
        ProxyPassReverse / http://origin.example.com/
        ProxyPassReverseCookieDomain origin.example.com www.example.com
        ProxyPreserveHost on
    </IfModule>
    <IfModule pagespeed_module>
        ModPagespeed On
        ModPagespeedMapRewriteDomain www.example.com origin.example.com
        ModPagespeedMapRewriteDomain example.com origin.example.com
        #ModPagespeedEnableFilters add_head
        #ModPagespeedEnableFilters combine_heads
        #ModPagespeedEnableFilters inline_import_to_link
        #ModPagespeedEnableFilters outline_css
        #ModPagespeedEnableFilters outline_javascript
        #ModPagespeedEnableFilters move_css_above_scripts
        #ModPagespeedEnableFilters move_css_to_head
        #ModPagespeedEnableFilters combine_css
        #ModPagespeedEnableFilters rewrite_css
        #ModPagespeedEnableFilters fallback_rewrite_css_urls
        #ModPagespeedEnableFilters rewrite_style_attributes
        #ModPagespeedEnableFilters rewrite_style_attributes_with_url
        #ModPagespeedEnableFilters flatten_css_imports
        #ModPagespeedEnableFilters prioritize_critical_css
        #ModPagespeedEnableFilters make_google_analytics_async
        #ModPagespeedEnableFilters rewrite_javascript
        #ModPagespeedEnableFilters rewrite_javascript_external
        #ModPagespeedEnableFilters rewrite_javascript_inline
        #ModPagespeedEnableFilters include_js_source_maps
        #ModPagespeedEnableFilters combine_javascript
        #ModPagespeedEnableFilters canonicalize_javascript_libraries
        #ModPagespeedEnableFilters inline_css
        #ModPagespeedEnableFilters inline_google_font_css
        #ModPagespeedEnableFilters inline_javascript
        #ModPagespeedEnableFilters local_storage_cache
        #ModPagespeedEnableFilters rewrite_images
        #ModPagespeedEnableFilters convert_jpeg_to_progressive
        #ModPagespeedEnableFilters convert_png_to_jpeg
        #ModPagespeedEnableFilters convert_jpeg_to_webp
        #ModPagespeedEnableFilters convert_to_webp_lossless
        #ModPagespeedEnableFilters insert_image_dimensions
        #ModPagespeedEnableFilters inline_images
        #ModPagespeedEnableFilters recompress_images
        #ModPagespeedEnableFilters recompress_jpeg
        #ModPagespeedEnableFilters recompress_png
        #ModPagespeedEnableFilters recompress_webp
        #ModPagespeedEnableFilters convert_gif_to_png
        #ModPagespeedEnableFilters strip_image_color_profile
        #ModPagespeedEnableFilters strip_image_meta_data
        #ModPagespeedEnableFilters resize_images
        #ModPagespeedEnableFilters resize_rendered_image_dimensions
        #ModPagespeedEnableFilters inline_preview_images
        #ModPagespeedEnableFilters resize_mobile_images
        #ModPagespeedEnableFilters remove_comments
        #ModPagespeedEnableFilters collapse_whitespace
        #ModPagespeedEnableFilters elide_attributes
        #ModPagespeedEnableFilters extend_cache
        #ModPagespeedEnableFilters extend_cache_css
        #ModPagespeedEnableFilters extend_cache_images
        #ModPagespeedEnableFilters extend_cache_scripts
        #ModPagespeedEnableFilters extend_cache_pdfs
        #ModPagespeedEnableFilters sprite_images
        #ModPagespeedEnableFilters rewrite_domains
        #ModPagespeedEnableFilters trim_urls
        #ModPagespeedEnableFilters pedantic
        #ModPagespeedEnableFilters remove_quotes
        #ModPagespeedEnableFilters add_instrumentation
        #ModPagespeedEnableFilters convert_meta_tags
        #ModPagespeedEnableFilters defer_javascript
        #ModPagespeedEnableFilters dedup_inlined_images
        #ModPagespeedEnableFilters lazyload_images
        #ModPagespeedEnableFilters insert_dns_prefetch
        #ModPagespeedEnableFilters in_place_optimize_for_browser
    </IfModule>
    <Location /pagespeed_admin>
        AuthName "PageSpeed Admin"
        AuthType Basic
        AuthUserFile /home/example/etc/htpasswd
        Require valid-user
        Satisfy any
        Allow from 127.0.0.1
    </Location>
</VirtualHost>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.