Socket.IO/Websockets failing to work in DigitalOcean

February 21, 2015 3.4k views

Hello there.
I'm trying to run a socket.io application with DigitalOcean. I can reach and connect to the application website just fine. However, attempting to use the websocket portion of the website fails. It simply does nothing at all when clicked on. I've been looking into this and I can't figure out why this is happening, at all.

My nginx configuration is configured to allow websockets, as seen here:

user www-data; 
worker_processes 4; 
pid /run/nginx.pid;

events { 
worker_connections 768; 
# multi_accept on; 
}

http {

## 
# Basic Settings 
##

sendfile on; 
tcp_nopush on; 
tcp_nodelay on; 
keepalive_timeout 65; 
types_hash_max_size 2048; 
# server_tokens off; 
# server_names_hash_bucket_size 64; 
# server_name_in_redirect off;

include /etc/nginx/mime.types; 
default_type application/octet-stream;

## 
# Logging Settings 
##

access_log /var/log/nginx/access.log; 
error_log /var/log/nginx/error.log;

## 
# Gzip Settings 
##

gzip on; 
gzip_disable "msie6";

# gzip_vary on; 
# gzip_proxied any; 
# gzip_comp_level 6; 
# gzip_buffers 16 8k; 
# gzip_http_version 1.1; 
# gzip_types text/plain text/css application/json application/x-javas$

## 
# nginx-naxsi config 
## 
# Uncomment it if you installed nginx-naxsi

#include /etc/nginx/naxsi_core.rules;

## 
# nginx-passenger config 
## 
# Uncomment it if you installed nginx-passenger 
##

#passenger_root /usr; 
#passenger_ruby /usr/bin/ruby;

## 
# Server Settings (DO NOT TOUCH) 
## 
server { 
listen 80; 
server_name c00l;

large_client_header_buffers 8 32k;

location / { 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_set_header Host $http_host;

proxy_set_header X-NginX-Proxy true;

proxy_buffers 8 32k; 
proxy_buffer_size 64k;

proxy_pass http://localhost:5000; 
proxy_redirect off;

proxy_http_version 1.1; 
proxy_set_header Upgrade $http_upgrade; 
proxy_set_header Connection "upgrade"; 
} 
}

## 
# Virtual Host Configs 
##

include /etc/nginx/conf.d/*.conf; 
include /etc/nginx/sites-enabled/*;

}

#mail { 
# # See sample authentication script at: 
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript 
# 
# # auth_http localhost/auth.php; 
# # pop3_capabilities "TOP" "USER"; 
# # imap_capabilities "IMAP4rev1" "UIDPLUS"; 
# 
# server { 
# listen localhost:110; 
# protocol pop3; 
# proxy on; 
# } 
# 
# server { 
# listen localhost:143; 
# protocol imap; 
# proxy on; 
# listen localhost:110; 
# protocol pop3; 
# proxy on; 
# } 
# 
# server { 
# listen localhost:143; 
# protocol imap; 
# proxy on; 
# } 
#} 

A normal netstat shows that the ports are active:

tcp        0      0 localhost:6379          localhost:39250         ESTABLISHED
tcp        0      0 localhost:39253         localhost:6379          ESTABLISHED
tcp        0      0 localhost:6379          localhost:39251         ESTABLISHED
tcp        0      0 107.170.53.195:ssh      103.41.124.13:36058     ESTABLISHED
tcp        0      0 localhost:39254         localhost:6379          ESTABLISHED
tcp        0      0 107.170.53.195:5000     107-196-109-252.l:55708 ESTABLISHED
tcp        0      0 localhost:6379          localhost:39254         ESTABLISHED
tcp        0      0 localhost:4444          localhost:44273         ESTABLISHED
tcp        0      0 localhost:39251         localhost:6379          ESTABLISHED
tcp        0      0 localhost:39255         localhost:6379          ESTABLISHED
tcp        0    128 107.170.53.195:ssh      107-196-109-252.l:55781 ESTABLISHED
tcp        0      0 localhost:39249         localhost:6379          ESTABLISHED
tcp        0      0 localhost:39250         localhost:6379          ESTABLISHED
tcp        0      0 localhost:6379          localhost:39255         ESTABLISHED
tcp        0      0 107.170.53.195:ssh      115.239.228.6:45629     ESTABLISHED
tcp        0      0 107.170.53.195:5000     107-196-109-252.l:55711 ESTABLISHED
tcp        0      0 localhost:6379          localhost:39252         ESTABLISHED
tcp        0      0 localhost:44273         localhost:4444          ESTABLISHED
tcp       28      0 107.170.53.195:59904    productsearch.ubu:https CLOSE_WAIT
tcp        0      0 localhost:39252         localhost:6379          ESTABLISHED
tcp        0      0 localhost:5900          localhost:57267         ESTABLISHED
tcp        0      0 localhost:6379          localhost:39253         ESTABLISHED
tcp        0      0 localhost:57267         localhost:5900          ESTABLISHED
tcp        0      0 localhost:6379          localhost:39249         ESTABLISHED
tcp6       1      0 ip6-localhost:39893     ip6-localhost:ipp       CLOSE_WAIT

netstat -an | grep "LISTEN" says the ports are listening and are responsive:

tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 
tcp 0 0 127.0.0.1:5900 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 
tcp 0 0 127.0.0.1:4444 0.0.0.0:* LISTEN 
tcp6 0 0 :::80 :::* LISTEN 
tcp6 0 0 :::22 :::* LISTEN 
tcp6 0 0 ::1:631 :::* LISTEN

The terminals running the applications are showing no errors and seem to be working absolutely fine. I really cannot figure out why this is failing. What is stranger is that I can connect to it FROM the SERVER's localhost and from there the websocket application will run as it should... Is there something I need to configure?

The application in question that I'm trying to run is using socket.io to run an emulated Windows computer. This project is named socket.io-computer and the source code is available to view at http://github.com/kevin-roark/socket.io-computer . My server's CPU usage is a little high (only about 20% however), but that shouldn't have any affect on whether or not the websockets work... At least I don't think.

These applications are using port 5000 and port 6001, which should be absolutely fine, at least I think so. I've read all the readmes but still no luck and I've configured it pretty heavily too. Any help with this one?

The server in question is running Ubuntu 14.04 LTD (64-bit).

1 comment
Be the first one to answer this question.