Rewrite POST into GET?

I’m working on a facebook application built using Rails. This is my
first time deploying a Rails site, and I’m setting up Capistrano to do
the heavy lifting. I’ve got it creating a “down for maintenance” file
that I would like served to all facebook requests when I’m updating
things, but facebook always sends a POST request. This causes Nginx to
respond with a 405 and report “client sent invalid method…”;
obviously you can’t really POST to a static page.

Is there a way I can re-direct POST requests to GET requests or force
Nginx to return the static page regardless of the method used to
access it? My backup plan is to deploy a second app on a different set
of ports that always returns the “down for maintenance” message…
but it seems silly to run one app to report you’re upgrading another.

Thanks!

Mark

hi mark.

maybe something like …


location / {

if ($request_method = POST ) {
rewrite (.*) /system_maintenance.html
proxy_pass http://rails_app;
}

}

ciao :slight_smile:

On Thu, Feb 14, 2008 at 02:12:35AM -0800, Mark S. wrote:

access it? My backup plan is to deploy a second app on a different set
of ports that always returns the “down for maintenance” message…
but it seems silly to run one app to report you’re upgrading another.

The attached patch adds the “post_to_static” directive:

     location / {
          post_to_static  on;
     }

or

 server {

      if ( maintaince  ) {

          ...
          break;

          post_to_static  on;
      }

Wow Igor, that was fast! Thank you!

I downloaded the development version of nginx (I’d been using the
previous stable version 0.5.35), and applied the patch. Unfortunately,
when I started the new version of the server, the post_to_static
didn’t change the 405 result sent back to facebook.

My configuration file looks like this:

http {

server {
listen 8080;
server_name localhost;

set the max size for file uploads to 50 MB.

client_max_body_size 50M;

     #charset koi8-r;

     access_log  logs/host.vhost.access.log  main;

root /usr/local/webapps/listage/current/public;

if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
post_to_static on;
}

     location / {
     ...
     }
 }

}

Do I have that right?

I tried it manually and got the same error:

mark$ telnet localhost 8080
Trying 127.0.0.1…
Connected to 127.0.0.1.
Escape character is ‘^]’.
POST / HTTP/1.0
Content-Length: 0

HTTP/1.1 405 Not Allowed
Server: nginx/0.6.26
Date: Fri, 15 Feb 2008 01:12:06 GMT
Content-Type: text/html
Content-Length: 173
Connection: close

405 Not Allowed

405 Not Allowed


nginx/0.6.26 Connection closed by foreign host.

Mark

On Thu, Feb 14, 2008 at 05:13:57PM -0800, Mark S. wrote:

...

root /usr/local/webapps/listage/current/public;
}
}

Do I have that right?

I was wrong - the configuration should be changed to:

server {

if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
break;
}

location = /system/maintenance.html {
post_to_static on;
}

Hey Igor,

Again thank you for such a fast response. I tried the new
configuration and it works perfectly!

Mark