Install nginx with pagespeed mod, flv and mp4

Installing nginx with google pagespeed_mod, flv module, mp4 module and ngx_cache_purge on Debian.

with pagespeed_mod flv and mp4

Install dependencies:

apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev

Download ngx_pagespeed:

$ cd ~
 $ wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.6.29.5-beta.zip
 $ unzip release-1.6.29.5-beta.zip # or unzip release-1.6.29.5-beta
 $ cd ngx_pagespeed-release-1.6.29.5-beta/
 $ wget https://dl.google.com/dl/page-speed/psol/1.6.29.5.tar.gz
 $ tar -xzvf 1.6.29.5.tar.gz # expands to psol/

Download ngx_cache_purge:

$ wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz
$ tar -xvf ngx_cache_purge-2.1.tar.gz

Download and build nginx:

please check http://nginx.org/en/download.html for the latest version

$ wget http://nginx.org/download/nginx-1.4.5.tar.gz
 $ tar -xvzf nginx-1.4.5.tar.gz
 $ cd nginx-1.4.5/
 $ ./configure --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --add-module=/home/user/tmp/ngx_pagespeed-release-1.6.29.5-beta --add-module=/home/user/tmp/ngx_cache_purge-2.1
 $ make
 $ make install

In your nginx.conf, add to the main or server block:

pagespeed on;

# needs to exist and be writable by nginx www-data:www-data

pagespeed FileCachePath /var/ngx_pagespeed_cache;

In every server block where pagespeed is enabled add:

#  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 ~ "^/ngx_pagespeed_static/" { }
 location ~ "^/ngx_pagespeed_beacon$" { }
 location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
 location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
 location /pagespeed_console { allow 127.0.0.1; deny all; }

Make use of nginx microcache!!!

in /etc/nginx/nginx.conf add to http{}

fastcgi_cache_path /dev/shm/microcache levels=1:2 keys_zone=microcache:20m max_size=1000m inactive=5m;

and per site.conf

# pass the PHP scripts to FastCGI server listening on a UNIX socket
 location ~ \.php$ {
 # Setup var defaults
 set $no_cache "";
 # If non GET/HEAD, don't cache & mark user as uncacheable for 1 second via cookie
 if ($request_method !~ ^(GET|HEAD)$) {
 set $no_cache "1";
 }
 # Drop no cache cookie if need be
 # (for some reason, add_header fails if included in prior if-block)
 if ($no_cache = "1") {
 add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
 add_header X-Microcachable "0";
 }
 # Bypass cache if no-cache cookie is set
 if ($http_cookie ~* "_mcnc") {
 set $no_cache "1";
 }
 # Bypass cache if flag is set
 fastcgi_no_cache $no_cache;
 fastcgi_cache_bypass $no_cache;
 fastcgi_cache microcache;
 fastcgi_cache_key $server_name|$request_uri;
 fastcgi_cache_valid 404 30m;
 fastcgi_cache_valid 200 10s;
 fastcgi_max_temp_file_size 1M;
 fastcgi_cache_use_stale updating;
 fastcgi_pass_header Set-Cookie;
 fastcgi_pass_header Cookie;
 fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
 #fastcgi_pass 127.0.0.1:9000;
 fastcgi_pass unix:/var/run/php5-fpm.sock;
 fastcgi_index index.php;
 include fastcgi.conf;
 }