Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Using the development version of nginx (1.3.12). In my relevant file under sites-enabled:

upstream twisted {
    server 127.0.0.1:8088;
}

server {  

    listen   80; ## listen for ipv4  

    server_name  *.clurn.co.uk clurn.co.uk;  

    access_log  /var/log/nginx/clurn.co.uk.access.log;  

    location / {  
            root   /var/www/clurn.co.uk;  
            index  index.html index.htm;  

    }  

    location /websocket {  
            proxy_pass http://twisted;  
            proxy_http_version 1.1;  
            proxy_set_header Upgrade $http_upgrade;  
            proxy_set_header Connection "Upgrade";  
    }  

    location /websocket/server {  
            deny all;  
    }  

    [...snip...]
}

Only difference from the example on nginx's site is the capital u on upgrade, which seemed to be necessary for the Autobahn and/or txWS instances to recognise the websockets correctly (I can't remember which one it was atm).

Now, if I access the websockets via 127.0.0.1:8088 on the server, then it appears to work, but if I access it via 127.0.0.1/websockets it doesn't, so there has to be something wrong with the marshalling of the packets via nginx.

If I run netcat -l -p 8088 instead of the Twisted websocket backend, I can see that the requests are identical if accessed via nginx or directly (originally they weren't, but changing the "upgrade" to "Upgrade" made the header line Connection: Upgrade the same), so this part is proxying correctly.

However, if I telnet into 127.0.0.1:8088 and 127.0.0.1/websocket, copying and pasting the correct request, I get a response with the direct 127.0.0.1:8088, and do not with the 127.0.0.1/websocket. What am I doing wrong, and how can I set it up to allow websockets on both sides?

share|improve this question
    
127.0.0.1 /websockets and 127.0.0.1:8088 / are different requests. Is it still working when you request 127.0.0.1:8088 /websockets? –  VBart Feb 28 '13 at 20:39
1  
Did you solve this? I'm getting pretty much the same behavior. I was able to successfully proxy through nginx with a websocket-only server (all the set_headers being at the root level of the server config), but get no responses otherwise. –  outofculture Mar 22 '13 at 18:11

1 Answer 1

up vote 1 down vote accepted

I think the problem is buffering. Set:

proxy_buffering off;

inside the websocket location config.

share|improve this answer
    
Unfortunately I no longer have the setup so can't check. But it sounds like if it solved your issue (if it were the same) then it may as well be marked as correct. –  socksy Nov 8 '13 at 3:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.