Hi there,
For my purposes, I only want to run pagespeed filters on "public" pages
served through my application, as these are the pages I are concerned with
the performance of / I want to avoid any potential issues with more dynamic
pages being rewritten.
Right now I are able to accomplish this with Apache and mod_pagespeed with
the following configuration within pagespeed.conf;
FilterDeclare pagespeed CONTENT_SET
FilterProvider pagespeed MOD_PAGESPEED_OUTPUT_FILTER \
"%{resp:X-Pagespeed-Enable} == 'true'"
FilterChain pagespeed
This config only enables pagespeed when the response from the
application contains the header 'X-Pagespeed-Enable: true', which it emits
when relevant.
However, I am struggling to do this with nginx. I have a test server setup
with nginx proxying our application through a Unix socket with a configuration
like this (simplified);
upstream app {
server unix:/foo.sock fail_timeout=0;
}
server {
listen 80;
root /app/public;
try_files $uri/index.html $uri @app;
# Pagespeed
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
location @app {
# Both X-Debug-1 and X-Debug-2 successfully contain the
# X-Pagespeed-Enable header returned by the server
add_header "X-Debug-1" $upstream_http_x_pagespeed_enable;
add_header "X-Debug-2" $sent_http_x_pagespeed_enable;
}
# Ensure requests for pagespeed optimized resources go to the pagespeed
# handler, and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
}
However, I cannot figure out how to make pagespeed or its filters conditional
on the value of the $upstream_http_x_pagespeed_enable /
$sent_http_x_pagespeed_enable (same value) variable.
I've tried using if statements similar to that outlined by the tests
various permutations of if statements / maps / variables / etc, but I can't
seem to find a working approach.
I suspect that the response variables aren't set at the point that they are
being evaluated in the config, but I'm not well versed enough in nginx to say
for sure.
Does anyone have any suggestions / thoughts on how I might accomplish this?
Greatly appreciated,
Ash