I'm trying to get nginx to serve websockets from a directory on port 80, rather than the root domain on the port which node.js is listening on.
Connecting directly to the port works, but trying to connect through the directory specified in nginx config I keep getting code 502 from the browser and 301 when using curl.
My nginx server config looks like:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /www;
index index.html index.htm index.php;
server_name my_ip;
location /smth-chat/ {
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_pass http://127.0.0.1:3335;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
try_files $uri $uri/ =404;
}
location /something-something/ {
try_files $uri $uri/ /something-something/index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
my_ip/something-something/chat serves an html page with a socket.io chat which tries to connect to my_ip/smth-chat via websocket (forced in socket.io settings).
An entry in my nginx error.log looks like:
2015/09/07 17:42:15 [error] 19277#0: *264 upstream prematurely closed connection while reading response header from upstream, client: some_ip, server: my_ip, request: "GET /smth-chat/?EIO=3&transport=websocket HTTP/1.1", upstream: "http://127.0.0.1:3335/smth-chat/?EIO=3&transport=websocket", host: "my_ip"
The client-side socket.io is initiated with:
var socket = io('http://my_ip', {
path: '/smth-chat',
transports: ['websocket']
});
What am I doing wrong?