A bit of ajax works fine locally but breaks on nginx

0 views
Skip to first unread message

Max Williams

unread,
Jul 24, 2008, 12:01:53 PM7/24/08
to rubyonrails...@googlegroups.com
I have an ajax call that works fine locally:

#in my view
<%= link_to_remote "Add a New Property", { :url =>
admin_properties_path, :method => 'POST' } %>

This calls the create action in my admin/properties controller. But, on
our server, which uses nginx and a mongrel cluster, i get this error
reported in firebug when the post request is sent:

<html>
<head><title>411 Length Required</title></head>
<body bgcolor="white">
<center><h1>411 Length Required</h1></center>
<hr><center>nginx/0.6.29</center>
</body>
</html>

Can anyone explain what's going on here, and how to fix it? My
knowledge of server mechanics is shaky at best and i'm not sure what the
'length' thing is in reference to.

thanks
max
--
Posted via http://www.ruby-forum.com/.

Max Williams

unread,
Jul 24, 2008, 12:03:34 PM7/24/08
to rubyonrails...@googlegroups.com
Oh, and this is the generated html from the link_to_remote:

<a href="#" onclick="jQuery.ajax({async:true, dataType:'script',
type:'POST', url:'/admin/properties'}); return false;">

Max Williams

unread,
Jul 24, 2008, 12:56:35 PM7/24/08
to rubyonrails...@googlegroups.com
Max Williams wrote:
> Oh, and this is the generated html from the link_to_remote:
>
> <a href="#" onclick="jQuery.ajax({async:true, dataType:'script',
> type:'POST', url:'/admin/properties'}); return false;">

I actually fixed this, on my second attempt, i'd still be very
interested in finding out why it broke though.

Attempt 1 - (FAIL)
Read that a remote post request with no parameters sometimes breaks over
length, so i added a dummy parameter in there.

Attempt 2 - (WIN)
Changed it to a remote get request instead.

It's not really a true win though as i'm still none the wiser why the
post request worked locally but broke on our server.

Aníbal Rojas

unread,
Jul 25, 2008, 10:46:18 AM7/25/08
to Deploying Rails
Whould you please post you Nginx config?

--
Aníbal Rojas
http://hasmanydevelopers.com
http://rubycorner.com
http://anibal.rojas.com.ve

On Jul 25, 11:56 am, Max Williams <ruby-forum-incom...@andreas-s.net>
wrote:

Max Williams

unread,
Jul 25, 2008, 11:24:33 AM7/25/08
to rubyonrails...@googlegroups.com
I assume you mean this file (i didn't write this) - here you go: thanks!

#/config/nginx/rails_nginx_vhost.conf

upstream fake_application {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
}

server {
listen 80;
server_name dev.fakedomain.com assets0.fakedomain.com
assets1.fakedomain.com assets2.fakedomain.com assets3.fakedomain.com;
root /var/www/apps/fake_application/current/public;
access_log
/var/www/apps/fake_application/shared/log/dev.fakedomain.com-access.log;
error_log
/var/www/apps/fake_application/shared/log/dev.fakedomain.com-error.log;
client_max_body_size 50M;

if (-f $document_root/system/maintenance.html){
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;

if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
if (!-f $request_filename) {
proxy_pass http://fake_application;
break;
}
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;

Aníbal Rojas

unread,
Jul 26, 2008, 9:31:21 AM7/26/08
to Deploying Rails
The proxy configuration looks good, I first tough it could be a
missing header.

Googled a little, and it looks like Nginx chokes on a empty POST
request, currently your alternatives looks like switching to GET or
adding a dumb variable to the POST.

This is interesting, will play a little with it maybe post it to Nginx
list.

Best regards,

--
Aníbal

On Jul 26, 10:24 am, Max Williams <ruby-forum-incom...@andreas-s.net>
wrote:
>                         proxy_passhttp://fake_application;

Max Williams

unread,
Jul 26, 2008, 8:11:14 PM7/26/08
to rubyonrails...@googlegroups.com
Thanks for looking at this anibal.

Like i said in my follow up post, above, my first attempt at fixing the
problem was to add a dummy parameter to the post request, and it still
broke. I did fix it by doing a get instead though.

thanks
max

Caesar Indra

unread,
Aug 10, 2008, 11:29:49 PM8/10/08
to rubyonrails...@googlegroups.com

Hi all,

I'm also having the same issue. What's weird is that the Content-Length
is clearly 114 here. It's sending a PUT request instead of POST. Can
anyone help? Thanks in advance!


Host www.***.com
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;
rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
X-Requested-With XMLHttpRequest
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Referer http://www.***.com/***/1/***
Content-Length 114
Cookie
_****_session=BAh7CjoPbGFzdF9sb2dpbnU6CVRpbWUNYR0bgAAAYL86EHJlcXVlc3RfdXJp%250AMDoMY3NyZl9pZCIlMDg2ZDNhMDc5MTVlMjU5OTc5YzNiYWU5ODMzMTJhOGUi%250ACmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7%250ABzoLbm90aWNlMDoMd2FybmluZzAGOgpAdXNlZHsHOwpUOwtUOgl1c2Vybzo1%250AQWN0aXZlUmVjb3JkOjpBc3NvY2lhdGlvbnM6OkJlbG9uZ3NUb0Fzc29jaWF0%250AaW9uCToLQG93bmVybzoLRGV0YWlsCDoMQHBlcnNvbkALOhBAYXR0cmlidXRl%250Ac3sLIhV3b3JsZF92aXNpYmlsaXR5Ig9ldmVyeXRoaW5nIhVpbmZvcm1hdGlv%250Abl90eXBlIhFFbWFpbEFkZHJlc3MiD3VwZGF0ZWRfb24iGDIwMDgtMDgtMDQg%250AMDU6NDk6MTUiB2lkIgYyIhNpbmZvcm1hdGlvbl9pZCIGMSIOcGVyc29uX2lk%250AIgYxOhZAYXR0cmlidXRlc19jYWNoZXsAOgxAbG9hZGVkVDoMQHRhcmdldG86%250ACVVzZXIXOiVAZGV0YWlsX21lbWJlcnNoaXBfcmVsYXRpb25zaGlwczA6KUB1%250Ac2VyX3Byb2ZpbGVfZW1haWxfYWRkcmVzc19yZXF1ZXN0czA6E0BoaXN0b3J5%250AX2l0ZW1zMDsSewoiD2FjY291bnRfaWQiBjEiFW9wdGlvbmFsX2RhdGVfaWQw%250AIgl0eXBlIglVc2VyIgdpZCIGMSIMbmFtZV9pZCIGMToNQGFjY291bnQwOihA%250AdXNlcl9wcm9maWxlX2VtYWlsX2FkZHJlc3NfcmVxdWVzdDA6DUBkZXRhaWxz%250AMDojQGRldGFpbF9lbWFpbF9hZGRyZXNzX3JlcXVlc3RzMDoQQGJpcnRoX2Rh%250AdGUwOhRAZ3JvdXBzX21hbmFnZWQwOhxAZW1haWxfYWRkcmVzc19yZXF1ZXN0%250AczA6HUBtYW5hZ2VyX3N0YXR1c19yZXF1ZXN0czA7E3sAOgxAZ3JvdXBzMDor%250AQGRlbGV0ZV9wcmltYXJ5X2VtYWlsX2FkZHJlc3NfcmVxdWVzdHMwOhFAbWVt%250AYmVyc2hpcHMwOiFAZ3JvdXBfbWFuYWdlcl9yZWxhdGlvbnNoaXBzMDoKQG5h%250AbWUwOhBAcmVmbGVjdGlvbm86NEFjdGl2ZVJlY29yZDo6UmVmbGVjdGlvbjo6%250AQXNzb2NpYXRpb25SZWZsZWN0aW9uDToYQHRocm91Z2hfcmVmbGVjdGlvbkY6%250AE0BhY3RpdmVfcmVjb3JkYwtEZXRhaWw6EEBjbGFzc19uYW1lIgtQZXJzb246%250AC0BrbGFzc2MLUGVyc29uOgtAbWFjcm86D2JlbG9uZ3NfdG86DUBvcHRpb25z%250AewA7JjoLcGVyc29uOhZAcHJpbWFyeV9rZXlfbmFtZSIOcGVyc29uX2lk--020f3f75cdb3d084d5b4c2dccef5c941eff0b6c0;
email_address=***%40hotmail.com;
connection=4e210ec5836a6b4fbb0afe35c18eacb9

Reply all
Reply to author
Forward
0 new messages