3 messages in ru.sysoev.nginxRe: new nginx module: notice
FromSent OnAttachments
Keith RarickJun 15, 2007 1:36 pm 
Igor SysoevJun 16, 2007 4:33 am 
Keith RarickJun 18, 2007 10:46 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: new nginx module: noticeActions...
From:Igor Sysoev (is-G@public.gmane.org)
Date:Jun 16, 2007 4:33:38 am
List:ru.sysoev.nginx

On Fri, Jun 15, 2007 at 01:36:46PM -0700, Keith Rarick wrote:

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.

error_page 503 =200 /notice.html;

location / {

if (-f /var/www/notice.html) { return 503; }

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