Opened 7 years ago

Closed 6 years ago

#522 closed defect (invalid)

websocket connect failed with non default_server

Reported by: 雁鸣 周 Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.4.x
Keywords: WebSocket Cc:
uname -a: Linux li472-198 3.12.6-x86_64-linode36 #2 SMP Mon Jan 13 18:54:10 EST 2014 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.4.6
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed' --with-ipv6

Description

WebSocket connection to 'ws://test.com/websocket/notification' failed: Error during WebSocket handshake: Unexpected response code: 302

works fine with default_server or direct to backend server.


upstream  backend  {
    server   localhost:8080;
    server   localhost:8081;
}
server {
     listen   80 default_server;
             location ~ ^/websocket/ {
             proxy_pass http://backend;
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection "upgrade";
     }
     location  / {
             proxy_pass  http://backend;
             proxy_redirect    off;
             proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
             proxy_set_header  X-Real-IP  $remote_addr;
             proxy_set_header  Host $http_host;
     }
}
server {
     listen   80 default_server;
     server_name test.com;
             location ~ ^/websocket/ {
             proxy_pass http://backend;
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection "upgrade";
     }
     location  / {
             proxy_pass  http://backend;
             proxy_redirect    off;
             proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
             proxy_set_header  X-Real-IP  $remote_addr;
             proxy_set_header  Host $http_host;
     }
}

Change History (3)

comment:1 by Maxim Dounin, 6 years ago

Resolution: invalid
Status: newclosed

Configuration is written is invalid due to duplicate default_server and will be rejected by nginx on startup. Most likely, your nginx is working with another configuration and 302 is returned in accordance with the configuration.

comment:2 by 雁鸣 周, 6 years ago

Resolution: invalid
Status: closedreopened

sorry,actually I have no default_server on test.com,it's a mis-spelling here.so It's not due to duplicate default_server,because normal http request is successful.

Last edited 6 years ago by 雁鸣 周 (previous) (diff)

comment:3 by Maxim Dounin, 6 years ago

Resolution: invalid
Status: reopenedclosed

As already suggested, most likely reason is that nginx is working with different configuration, not the one was posted in the ticket and/or requests are handled in a server{} block which isn't included in the config snippet provided (see Server names article for details on server{} block selection).

Please use mailing list to ask for further help, if needed.

Note: See TracTickets for help on using tickets.