Hacker News new | past | comments | ask | show | jobs | submit login
Speed up your sites with PageSpeed for Nginx (googledevelopers.blogspot.com)
254 points by jdorfman on Apr 25, 2013 | hide | past | web | favorite | 42 comments

This didn't work for me, it did something very strange.

I have nginx set up to listen on ssl and proxy everything to my python backend in plain http (as well as serve static files)

Installing the pagespeed module (without even turning it on), caused nginx to revert to the default config (it just served the default nginx index.html and 404'd everything else) after the 3rd or 4th request.

Any ideas why this would happen?

I've narrowed down the problem to a specific change, and updated the installation instructions to use a release from last week before that change. People are reporting that this fixes it for them. I'm going to be putting out an updated version, probably, that also will have this issue fixed.

I had the same issue, even with the same config file, with no pagespeed directive, the version with the pagespeed module failed for static files for me.

[0426/064031:INFO:google_message_handler.cc(33)] Shutting down ngx_pagespeed root

I'm debugging this now. If you have anything atypical about your setup it would be great if you could post it to the bug: https://github.com/pagespeed/ngx_pagespeed/issues/292

I wish I didn't have to compile from source to install modules, I'd love to continue to use the official nginx YUM repo.

You can do this with Tengine [1], a version of Nginx that supports loadable modules: https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_pa...

[1] http://tengine.taobao.org/

If you're using Debian, dotdeb[1] comes with the ngnix-extras (includes the push stream module[2]) installed as well as some other goodies like passenger.

[1] http://www.dotdeb.org/2011/12/19/nginx-1-0-11-passenger-3-0-...

[2] https://github.com/wandenberg/nginx-push-stream-module

Am I the only one who is worried that modules like this introduce subtle and hard-to-find bugs in the served pages? It's a layer you don't usually look at when debugging web applications.

Good one. Anyone here got experience with the original Apache mod_pagespeed in production?

I've been thinking the same thing. Although, reading about how it works does help alleviate my concerns somewhat: https://github.com/pagespeed/ngx_pagespeed/wiki/Design. At the least, it seems like something worth playing around with.

Comments from when someone posted a link to a pre-alpha version: https://news.ycombinator.com/item?id=4638712

Does anyone know if this works when using Nginx as a proxy? That would be pretty killer if so.

Yup, in fact, that's exactly how ZippyKid integration is setup: https://www.zippykid.com/2013/04/23/partnership-with-google-...

It doesn't matter if the files are local or remote, ngx_pagespeed can fetch from both. Some docs on related functionality: https://developers.google.com/speed/docs/mod_pagespeed/domai...

Thanks for the link. I for one will be implementing this then! Probably start testing tonight actually (I'm excited).

Druiid, do you mind testing our instructions here? http://github.com/zippykid/nginx/ ?

Sure, I'll take a look at it. Might be able to send you guys some rpm instructions as well. We are a RH/CentOS shop.

Edit: Looking over your build files. I think I'm going to go ahead and create (or modify existing) spec files and throw together a github for an nginx RH tree. If anyone is interested in it when done, shoot me an e-mail through profile.

Can't edit again for some reason.. so here goes for anyone that is interested. Included modified spec file and built-RPMS:


Pretty sure github is going to yell at me about the binary files :P

I kept tripping up on the instructions, such as the git clone for your repo should be the anon one (git://) and final commands (debuild -us -uc) kept telling me that there were no upstream git.

I tried the scripts verbatim on a fresh Ubuntu 13.04 VM (64bit).

edit: Your deb link at the end of the readme is broken as well.

Thanks Josh, I'll update them tomorrow/saturday. Did you create an issue by any chance?

You've disabled issues so I cannot add one.

I am currently using nginx as a proxy to Apache+mod_wsgi. nginx serves the static files too. Do you know whether I should install this module for nginx or for Apache or both?

It does; that's definitely one of the intended uses.

Oooops, http://ngxpagespeed.com/ (their demonstration site) doesn't respond at the moment...

Still no response 8 hours down the line.

It is back now. You can apply single filters and check out the results. It's nice to play with.

Instructions on how to install/build deb package for Ubuntu/Debian here http://serverfault.com/questions/502764/how-to-build-nginx-1...

This is pretty sweet. What optimizations does it do other than offloading stuff to CDN?

All these: https://developers.google.com/speed/docs/mod_pagespeed/filte... So image optimization, css and js minification, cache extension, css combining, image spriting, ...

But offloading things to CDN is actually one of the things it doesn't do. You might be thinking of the PageSpeed Service [1] which is a Google-hosted version.

[1] https://developers.google.com/speed/pagespeed/service

Wow. Thanks for bringing the service to my attention! Cut the load times on my sites by a ton.

You can see the complete list of filters (40+) here: https://developers.google.com/speed/docs/mod_pagespeed/confi...

Note that docs above are for mod_pagespeed (Apache), but all of the same filters are available in nginx port as well - it's the same C++ code under the hood. In a nutshell: HTML, CSS, JS, and image optimization (resizing, recompression, WebP, auto-spriting, etc...)

Configuring ngx_pagespeed: https://github.com/pagespeed/ngx_pagespeed#how-to-use

Thank you that's more helpful. Looks like a great tool

Jeremy, image optimization/compression, javascript minification/combination etc are some of the benefits we've tested and had tremendous success with.

If I have a static directory of files is there any way to leverage this same code to just perform the optimizations on my html so I don't have to have the webserver do it (or so I don't have to run my own webserver)?

Probably not without some work. I think you have to get the PageSpeed Optimization Library and build it from source, as described here: https://github.com/pagespeed/ngx_pagespeed/wiki/Building-PSO...


Hmmm. I don't really know C++ well enough to do this myself. Oh well.

Seems like it would be super useful to have a command line version of this so I could take an html file, pipe it in and get out an optimized file, and then diff them so I can learn to make my pages better.

I suppose as a hack I could set up nginx with the plugin and then load each page through curl or something and diff them that way...

That wouldn't be a 100% match since it assumes HTTP headers and mangles them, too. For example, it probably uses the MIME type served by the proxied server to see whether it's css or js or whatever should be minified (I didn't check the sources for this).

With a pipe, it'd need to use heuristics to figure out what kind of file it is. That could be added, probably, but it's not entirely trivial.

Additionally, you'd miss out on all the HTTP header mangling, such as cache expiry settings.

I'm hoping heroku can support this. Maybe via a buildpack.

I'd love to get rid of using Sprockets and compiling assets.

ngx_pagespeed should take care of everything Sprockets does, right?

Yep, it'll concatenate files, minify them, etc., all the things you would expect. Perhaps the only caveat is: it doesn't do any dependency management, etc., which sprockets provides (if you actually use that part of it).

Wouldn't it be preferable to perform all of these optimizations once before page load to reduce the work that nginx has to do?

The work only has to be done once either way; all the file-based optimizations get cached, they're not run again on every page view.

I tried it on my own little webpage [1]. Results in short: 0.5 seconds to 0.9 seconds shorter load times. Beware, that I only have static content on that website.

[1] http://zufallsheld.de/2013/04/26/googles-nginx-plugin-ngx_pa...

This is brilliant, in principle. Getting some odd segfaults to do with libpthread-2.15.so on Ubuntu 12.10 though, so not sure what's going on there. I'll dig some more then file a bug...

Registration is open for Startup School 2019. Classes start July 22nd.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact