# Mongrel, Nginx, and AJAX not working

**URL:** <https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259>\
**Category:** Deployment\
**Created:** [July 24, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259 "2007-07-24T19:11:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [July 24, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259/1 "2007-07-24T19:11:49Z")

</div>

Under Apache / FastCGI, the following request is perfectly fine (as  
pulled  
from the browser’s View Source):

new  
Ajax.Request(‘[http://server/portals?editable=true&amp;update=portal\_list\_wrapper](http://server/portals?editable=true&amp;update=portal_list_wrapper)’,  
{asynchronous:true, evalScripts:true, method:‘get’})

However, under my new setup of Nginx and Mongrels, the call never  
returns. I  
get the proper log in production.log, stuff happens, and my browser just  
sits there twiddling it’s thumbs, never getting what it wants back  
(note:  
the update _is_ meant to be part of the GET string).

Has anyone else had a problem with this kind of setup? It feels that  
AJAX  
responses are getting stopped by Nginx but I can’t find anything out  
about  
this.

Thanks

Jason

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [July 24, 2007, 7:22pm UTC](https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259/2 "2007-07-24T19:22:44Z")

</div>

I know this isn’t the answer you’re looking for, but I ran into issues  
like this at least 3 times with lighttpd which is why I switched to  
nginx/mongrel. Each time I had a problem, firebug was essential in  
figuring out the problem… maybe take a look at the output from  
firebug and see if it helps…

-Vince

On 7/24/07, Jason R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the update _is_ meant to be part of the GET string).

–  
support independent business – [http://www.buyindie.net/](http://www.buyindie.net/)

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [July 24, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259/3 "2007-07-24T19:30:23Z")

</div>

Yeah, I’ve been watching Firebug, the request just spins until it times  
out.  
Getting back into the server works no problem, but there’s nothing  
coming  
back to my browser.

Thanks though. Interesting that you had this same problem with lighty.

Jason

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [July 24, 2007, 10:57pm UTC](https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259/4 "2007-07-24T22:57:10Z")

</div>

On Tue, 24 Jul 2007 13:10:42 -0400  
“Jason R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Under Apache / FastCGI, the following request is perfectly fine (as pulled  
> from the browser’s View Source):
> 
> new Ajax.Request(‘[http://server/portals?editable=true&amp;update=portal\_list\_wrapper](http://server/portals?editable=true&amp;update=portal_list_wrapper)’,  
> {asynchronous:true, evalScripts:true, method:‘get’})

What happens when you do & rather than & ?

–  
Zed A. Shaw

- Hate: [http://savingtheinternetwithhate.com/](http://savingtheinternetwithhate.com/)
- Good: [http://www.zedshaw.com/](http://www.zedshaw.com/)
- Evil: [http://yearofevil.com/](http://yearofevil.com/)

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [July 25, 2007, 6:57am UTC](https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259/5 "2007-07-25T06:57:44Z")

</div>

I had a very similar thing happen a few days ago and found a solution  
for my problem last night. That was Ajax request and firebug was  
showing the request as spinning and spinning…

The code was using Ajax.Request with a post (not a get), and worked  
fine just with mongrel, but through nginx, it was taking 120s to get  
back to that Complete state (and, although I’m not sure why, the  
reason it was taking 120s was probably that another Ajax request was  
being fired up every 120s).

The code responding to the request couldn’t be simpler:

```
 render :text => @mailbox.count.unseen

```

unseen happens to return an integer, not a string. And when trying  
with a string it worked

```
 render :text => "1234567890"

```

So just for a moment I thought it was the size of the request, but  
even a 1 byte string did not make any difference and still worked. So  
just changing that line to:

```
 render :text => @mailbox.count.unseen.to_s

```

fixed it for me. I have not attempted to figure out further what was  
happening, but my best theory is that the mime type returned by rails  
(mongrel?) may be different and nginx (or the browser?) is waiting  
for more to send the response back).

Not sure the same thing is happening in your case, but that may be  
worth looking more closely at the mime type.

## Cheers, Pascal.

[http://blog.nanorails.com](http://blog.nanorails.com)

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [July 27, 2007, 7:34pm UTC](https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259/6 "2007-07-27T19:34:27Z")

</div>

Follow-up # 2

Ignore previous post, I’m still stuck, though I know what’s wrong now.  
This  
is a site migration so traffic already exists to the url. I put up the  
site  
on the new box under a different url to see if it works and sure enough,  
it  
was snappy and perfect. Thinking all was good, I changed the DNS entry  
for  
the real URL and bam, back to a broken site.

So this is a load balancing issue then, or at least that’s what it looks  
like. I now know the whole stack works, but under a site that gets  
constant  
but in no ways heavy load, requests responses get lost. Literally.

As for the mime type, I’ll definitely look into that but all of my  
responses  
are RJS and thus strings.

Ug…

Jason

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [July 27, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259/7 "2007-07-27T17:02:08Z")

</div>

Follow-up:

I honestly do not know what I did, but it’s working now. I did install  
swiftiply to use it’s evented\_mongrel handler, so there might be  
something  
there that fixed the problem but I’m not sure.

Thanks for all of your suggestions.

Jason

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [July 27, 2007, 10:30pm UTC](https://www.ruby-forum.com/t/mongrel-nginx-and-ajax-not-working/110259/8 "2007-07-27T22:30:52Z")

</div>

So I just decided to bypass the problem and move to a different URL. Not  
going to deal with it if I can just get around it.

Jason
