new nginx module: notice

Keith Rarick kr at essembly.com
Sat Jun 16 00:36:46 MSD 2007


Hi, I'm Keith Rarick, and I recently wrote a small nginx module.

Find it at http://xph.us/software/nginx-notice/

Background:

Recently, facebook.com released an application framework so that
anyone can develop an application to be used by any of facebook's
users. We've made an application called "Causes". When the user
requests an application page on facebook, the facebook server makes a
request to the Causes server, reformats the response (adding a
facebook menu and style) and returns it to the user.

Our situation:

Now, when we update our database schema, we want to show a static page
during the downtime. We had been using something like this in
nginx.conf:

if (-f /var/www/notice.html) {
  rewrite ^(.*)$ /notice.html break;
  break;
}

location = /notice.html {
  root /var/downtime;
  break;
}

Unfortunately, every request from facebook uses POST, regardless of
the original request method from the user. The configuration above
returns a 4xx error to POST requests, which makes sense according to
the meaning of POST in HTTP. But since facebook is abusing POST, we
must also abuse POST. I want nginx to return /var/downtime/notice.html
with a 200 status in response to POST requests.

New module:

Therefore, I wrote a module that ignores the HTTP method and returns a
fixed body for every request it handles. Our configuration now looks
like this:

if (-f /var/www/notice.html) {
  rewrite ^(.*)$ /notice.html break;
  break;
}

location = /notice.html {
  notice /var/downtime/notice.html;
  break;
}

It works very well, but if there is a better or simpler way to
accomplish this I would love to know it. Otherwise, I hope someone
else may find this module useful.

kr





More information about the nginx mailing list