cmaxvv
July 24, 2008, 6:01pm
1
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:
411 Length Required
411 Length Required
nginx/0.6.29
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
cmaxvv
July 24, 2008, 6:03pm
2
Oh, and this is the generated html from the link_to_remote:
cmaxvv
July 24, 2008, 6:56pm
3
Max W. wrote:
Oh, and this is the generated html from the link_to_remote:
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.
cmaxvv
July 25, 2008, 4:47pm
4
Whould you please post you Nginx config?
–
Aníbal Rojas
http://anibal.rojas.com.ve
On Jul 25, 11:56 am, Max W. [email protected]
cmaxvv
July 25, 2008, 5:24pm
5
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;
}
}
cmaxvv
July 27, 2008, 2:11am
6
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
cmaxvv
July 26, 2008, 3:32pm
7
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 W. [email protected]
cmaxvv
November 16, 2008, 7:28pm
8
I’ve run into the same thing. Nginx chokes with a 411 error ("Length
required), when the jQuery Ajax call leaves the data parameter blank,
e.g. as in:
“jQuery.post(’/your_ajax_method’);”
The request never gets passed through to the app in this case.
After some Googling, it turned out the simple fix is to provide an empty
data set:
“jQuery.post(’/your_ajax_method’, {});”
This is probably a bug on the jQuery side.
cmaxvv
August 11, 2008, 5:29am
9
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%250A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3sAOgxAZ3JvdXBzMDor%250AQGRlbGV0ZV9wcmltYXJ5X2VtYWlsX2FkZHJlc3NfcmVxdWVzdHMwOhFAbWVt%250AYmVyc2hpcHMwOiFAZ3JvdXBfbWFuYWdlcl9yZWxhdGlvbnNoaXBzMDoKQG5h%250AbWUwOhBAcmVmbGVjdGlvbm86NEFjdGl2ZVJlY29yZDo6UmVmbGVjdGlvbjo6%250AQXNzb2NpYXRpb25SZWZsZWN0aW9uDToYQHRocm91Z2hfcmVmbGVjdGlvbkY6%250AE0BhY3RpdmVfcmVjb3JkYwtEZXRhaWw6EEBjbGFzc19uYW1lIgtQZXJzb246%250AC0BrbGFzc2MLUGVyc29uOgtAbWFjcm86D2JlbG9uZ3NfdG86DUBvcHRpb25z%250AewA7JjoLcGVyc29uOhZAcHJpbWFyeV9rZXlfbmFtZSIOcGVyc29uX2lk–020f3f75cdb3d084d5b4c2dccef5c941eff0b6c0;
email_address= %40hotmail.com ;
connection=4e210ec5836a6b4fbb0afe35c18eacb9
Max W. wrote:
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