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.

I have three server blocks (virtual hosts) for http and one for websocket in the nginx config (nginx 1.6.0, ubuntu 14.04).

server {
    listen 80;
    listen [::]:80;

    server_name h3400.domain.com;

    location / {
        proxy_pass http://localhost:3400/;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
    }
}

# this one for websocket on ws://h3400.domain.com:3000/
server {
    listen 3000;
    listen [::]:3000;

    server_name h3400.domain.com;

    location / {
            proxy_pass http://localhost:3001;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }
}

server {
    listen 80;
    listen [::]:80;

    server_name h3500.domain.com;

    location / {
        proxy_pass http://localhost:3500/;
        proxy_http_version 1.1;            
        proxy_set_header Host $host;
    }
}


server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name domain.com;

    ///other default nginx server block settings///
}

Now, in browser developer console (latest ff and chrome) I write:

var ws = new WebSocket('ws://domain.com:3000', 'Site');<br>
ws.readyState;

as result I get:

> 1

Connection strings I tested:

ws://domain.com:3000
ws://h3400.domain.com:3000
ws://h3500.domain.com:3000

And all connection strings give one result: 1. It means successful connection to the websocket backend.

It still throws connection to the 3001 port (I see it in logs of websocket backend), and doesn't check server_name or port, but it has been configured as server_name h3400.domain.com; and in start of every server block.

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.