Search code examples
javascriptgwtnginxejabberdemit

5920#0: *52 upstream timed out (110: Connection timed out) while connecting to upstream,


I tried to run emit(a gwt implemention of xmpp client) with ejabberd,and it works fine. I noticed that the developers of emit use a java servlet to proxy request to ejabberd:

https://github.com/EmiteGWT/hablar/blob/master/src/main/java/de/spieleck/servlets/ProxyServlet.java),

And I want to bypass this proxy,so I follow this post:

http://anders.conbere.org/blog/2011/05/03/get_xmpp_-_bosh_working_with_ejabberd_firefox_and_strophe/

But javascript client(complied from emit) takes long time to connect to ejabbered,and then disconnect quickly,and the nginx error log like this:

2012/10/06 17:04:33 [error] 5920#0: *52 upstream timed out (110: Connection timed out) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "POST /http-bind HTTP/1.1", 
upstream: "http://111.186.4.11:5280/http-bind", host: "127.0.0.1", referrer: "http://127.0.0.1/hablartest/HablarTest1.html"

Can anybody tell me what I did wrong?

My configuration: firefox-13 ejabberd-2.1.11 nginx-1.0.5 ubuntu-11.10

(since same client code(js code complied from gwt) with servlent proxy works fine,so I think it may be a nginx configuration problem)


Solution

  • Finally,I found out the problem:my proxy configuration like this:

     location ~ ^/http-bind {       
             proxy_pass http://localhost:5280;
     }
    

    So nginx will redirect all requests from 127.0.0.1:80 to localhost:5280

    This will work fine if I disconnected from Internet,but if I connect to Internet,my hosts file becomes:

    127.0.0.1       luya    localhost.localdomain   localhost
    111.186.4.11    luya    localhost.localdomain   localhost
    

    From my understanding,localhost will be "taken" as either 127.0.0.1 or 111.186.4.11 randomly,so it is this confusing caused problem.Solution is simple,changing proxy configuration

    from

    proxy_pass http://localhost:5280;
    

    to

     proxy_pass http://127.0.0.1:5280;