{"id":14047,"date":"2014-06-29T21:30:09","date_gmt":"2014-06-29T16:00:09","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=14047"},"modified":"2016-12-19T15:07:33","modified_gmt":"2016-12-19T09:37:33","slug":"install-ngx_pagespeed-module-with-nginx-on-ubuntu-14-04","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/install-ngx_pagespeed-module-with-nginx-on-ubuntu-14-04\/","title":{"rendered":"Install ngx_pagespeed module with nginx on ubuntu 14.04"},"content":{"rendered":"<p>PageSpeed speeds up your site and reduces page load time. This open-source webserver module automatically applies\u00a0web performance best practices\u00a0to pages and associated assets (CSS, JavaScript, images) without requiring that you modify your existing content or workflow.<a href=\"https:\/\/developers.google.com\/speed\/pagespeed\/module\" target=\"_blank\">Click here <\/a>for more technical information .<\/p>\n<p>By Default , nginx does not support dynamic loading of modules\u00a0,therefore we have to rebuild the Ngnix .<\/p>\n<p>Please refer given below steps<\/p>\n<p>Add Debian wheezy backports repository<\/p>\n<p>open \u00a0&#8220;\/etc\/sources.list&#8221; file in you system and append the following two lines, at\u00a0\u00a0the end of \u00a0file.<\/p>\n<pre>{.....}\r\ndeb http:\/\/ftp.de.debian.org\/debian\/ wheezy main\r\n  deb-src http:\/\/ftp.de.debian.org\/debian\/ wheezy main<\/pre>\n<p><strong>\u00a0<\/strong><\/p>\n<p>Update repositories package lists:<\/p>\n<pre style=\"color: #000000\">sudo apt-get update<\/pre>\n<p>Download backport source package &amp; build dependencies<\/p>\n<pre>apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev<\/pre>\n<p>Now create \u00a0a \u00a0folder in tmp directory to download the nginx source package into:<\/p>\n<pre>cd \/tmp &amp;&amp; mkdir pagespeed &amp;&amp; cd pagespeed<\/pre>\n<p>Download the nginx sources and the build dependencies:<\/p>\n<pre>apt-get source nginx\r\napt-get build-dep nginx<\/pre>\n<p>Once nginx backport source package is downloaded , let&#8217;s add the ngx_pagespeed module and extract it under modules folder<\/p>\n<pre>cd pagespeed\/nginx-1.4.6\/debian\/modules\r\nwget https:\/\/github.com\/pagespeed\/ngx_pagespeed\/archive\/v1.7.30.1-beta.zip\r\nunzip v1.7.30.1-beta.zip\r\ncd ngx_pagespeed-1.7.30.1-beta\/\r\nwget  -xzvf 1.7.30.1.tar.gz<\/pre>\n<p>&nbsp;<\/p>\n<p>Now, you have added ngx_pagespeed module successfully to the modules folder of the nginx , source package ready to be build with the other nginx modules . Before you can do that , one important step is \u00a0pending .<\/p>\n<p>Let&#8217;s edit the\u00a0<strong><span class=\"system\">debian\/rules<\/span>\u00a0<\/strong>file:<\/p>\n<pre>\/tmp\/pagespeed\/nginx-1.4.6\/debian\/rules<\/pre>\n<p>&nbsp;<\/p>\n<p>In that file you will find four<strong>\u00a0<span class=\"system\">config.status<\/span><\/strong>\u00a0sections (<strong><span class=\"system\">config.status.full<\/span>,\u00a0<span class=\"system\">config.status.light<\/span>,\u00a0<span class=\"system\">config.status.extras<\/span>,\u00a0<span class=\"system\">config.status.naxsi<\/span><\/strong>). Add the line<strong>\u00a0<span class=\"system\">&#8211;add-module=$(MODULESDIR)\/ngx_pagespeed \\<\/span>\u00a0<\/strong>to each of them, right before the<strong>\u00a0<span class=\"system\">$(CONFIGURE_OPTS) &gt;$@<\/span><\/strong>\u00a0line, e.g. as follows:<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/06\/module.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-14323\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/06\/module.png\" alt=\"module\" width=\"732\" height=\"389\" \/><\/a><\/p>\n<p>Now build the custom nginx package<\/p>\n<pre>\/tmp\/pagespeed\/nginx-1.4.6 &amp;&amp; sudo dpkg-buildpackage -b\r\n\r\n<\/pre>\n<p style=\"color: #000000\">You can now let the package building tools do their work while you relax.<\/p>\n<p style=\"color: #000000\">Once the command prompt appears again, you know that the building process is finished. Now the generated packages are located right outside the source package folder:<\/p>\n<pre style=\"color: #000000\"><span style=\"color: #000000\">\/tmp\/pagespeed\/ &amp;&amp;\u00a0ls \u00a0-l\u00a0<\/span><\/pre>\n<p style=\"color: #000000\">You will see something similar to the following:<\/p>\n<p style=\"color: #000000\"><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/06\/md2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-14325\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/06\/md2.png\" alt=\"md2\" width=\"790\" height=\"362\" \/><\/a><\/p>\n<p style=\"color: #000000\"><strong>Install the custom nginx package<\/strong><\/p>\n<p style=\"color: #000000\">We can now install nginx with PageSpeed . As you can see i will install two more packages , Those two are package dependencies that you must install along any of the four nginx packages<\/p>\n<pre style=\"color: #000000\">dpkg -i nginx-full_1.4.6-1ubuntu3_amd64.deb nginx-common_1.4.6-1ubuntu3_all.deb nginx_1.4.6-1ubuntu3_all.deb<\/pre>\n<p style=\"color: #000000\">In case you encounter the following error message:<\/p>\n<pre>dpkg: dependency problems prevent configuration of nginx-common:\r\n nginx-common depends on init-system-helpers<\/pre>\n<p style=\"color: #000000\">then just execute the following command:\u00a0which will fix any dependency problems you might you will face.<\/p>\n<pre style=\"color: #000000\"><span style=\"color: #000000\">sudo apt-get -f install<\/span><\/pre>\n<p style=\"color: #000000\">Let&#8217;s check if the PageSpeed module was built successfully:Create a new file in\u00a0\/etc\/apt\/preferences.d and add\u00a0the following lines in it and save<\/p>\n<pre>sudo nginx -V\r\nnginx version: nginx\/1.4.6 (Ubuntu)\r\nbuilt by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1) \r\nTLS SNI support enabled\r\nconfigure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=\/usr\/share\/nginx --conf-path=\/etc\/nginx\/nginx.conf --http-log-path=\/var\/log\/nginx\/access.log --error-log-path=\/var\/log\/nginx\/error.log --lock-path=\/var\/lock\/nginx.lock --pid-path=\/run\/nginx.pid --http-client-body-temp-path=\/var\/lib\/nginx\/body --http-fastcgi-temp-path=\/var\/lib\/nginx\/fastcgi --http-proxy-temp-path=\/var\/lib\/nginx\/proxy --http-scgi-temp-path=\/var\/lib\/nginx\/scgi --http-uwsgi-temp-path=\/var\/lib\/nginx\/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=\/root\/pagespeed\/nginx-1.4.6\/debian\/modules\/nginx-auth-pam --add-module=\/root\/pagespeed\/nginx-1.4.6\/debian\/modules\/nginx-dav-ext-module --add-module=\/root\/pagespeed\/nginx-1.4.6\/debian\/modules\/nginx-echo --add-module=\/root\/pagespeed\/nginx-1.4.6\/debian\/modules\/nginx-upstream-fair --add-module=\/root\/pagespeed\/nginx-1.4.6\/debian\/modules\/ngx_http_substitutions_filter_module --add-module=\/root\/pagespeed\/nginx-1.4.6\/debian\/modules\/ngx_pagespeed\r\n\r\n<\/pre>\n<h3 style=\"font-weight: bold;color: #2d2d2d\"><\/h3>\n<h3 style=\"font-weight: bold;color: #2d2d2d\">Configrue ngx_pagespeed module<\/h3>\n<p>we need to create a folder, which will cache your websites&#8217; files into:<\/p>\n<pre style=\"color: #000000\">sudo mkdir -p \/var\/ngx_pagespeed_cache\r\n\r\n sudo chown -R www-data:www-data \/var\/ngx_pagespeed_cache<\/pre>\n<p>After that open \u201cnginx.conf\u201d file<\/p>\n<pre>sudo vi \/etc\/nginx\/nginx.conf<\/pre>\n<p>add the lines &#8220;<span class=\"system\">pagespeed on &#8220;<\/span>and\u00a0<span class=\"system\">pagespeed FileCachePath &#8220;\/var\/ngx_pagespeed_cache&#8221;<\/span>\u00a0before any vhosts:<\/p>\n<pre>pagespeed on;\r\n        pagespeed FileCachePath \/var\/ngx_pagespeed_cache;\r\n\r\n        ##\r\n        # Virtual Host Configs\r\n        ##\r\n\r\n        include \/etc\/nginx\/conf.d\/*.conf;\r\n        include \/etc\/nginx\/sites-enabled\/*;<\/pre>\n<p>Now restart the nginx<\/p>\n<pre><span style=\"font-style: italic\">\/etc\/init.d\/nginx restart<\/span><\/pre>\n<p>we can configure PageSpeed individually or each vhost, e.g. like this and<\/p>\n<pre>vi \/etc\/nginx\/sites-available\/defaults<\/pre>\n<p>add the following lines<\/p>\n<pre>location ~ \"\\.pagespeed\\.([a-z]\\.)?[a-z]{2}\\.[^.]{10}\\.[^.]+\" { add_header \"\" \"\"; }\r\nlocation ~ \"^\/ngx_pagespeed_static\/\" { }\r\nlocation ~ \"^\/ngx_pagespeed_beacon\" { }\r\nlocation \/ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }\r\nlocation \/ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; }\r\nlocation \/ngx_pagespeed_message { allow 127.0.0.1; deny all; }\r\nlocation \/pagespeed_console { allow 127.0.0.1; deny all; }\r\n}<\/pre>\n<p>To stop your custom nginx package from being upgraded \u00a0in the future by &#8216;apt&#8217; with a more recent release of nginx,<\/p>\n<p>Create a new file in\u00a0\/etc\/apt\/preferences.d and add\u00a0the following lines in it and save<\/p>\n<pre>sudo vim \/etc\/apt\/preferences.d\/nginx\r\nPackage: nginx\r\nPin: version 1.4.6-1ubuntu3\r\nPin-Priority: 1001<\/pre>\n<address>\u00a0<\/address>\n<address>Thanks<\/address>\n<address>Prashant Sharma<\/address>\n","protected":false},"excerpt":{"rendered":"<p>PageSpeed speeds up your site and reduces page load time. This open-source webserver module automatically applies\u00a0web performance best practices\u00a0to pages and associated assets (CSS, JavaScript, images) without requiring that you modify your existing content or workflow.Click here for more technical information . By Default , nginx does not support dynamic loading of modules\u00a0,therefore we have [&hellip;]<\/p>\n","protected":false},"author":120,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[1174],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/14047"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/120"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=14047"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/14047\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=14047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=14047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=14047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}