i want bind nodejs to a url, like this: http://myproject.com/nodejs/
Currently, i have node in port 8080.
And i have nginx configuration :
upstream app {
server 127.0.0.1:8080;
}
server {
listen 80; ## listen for ipv4; this line is default and implied
root /home/myproject/www;
index index.html index.htm;
server_name myproject.com;
location /nodejs/ {
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://app/;
proxy_redirect off;
}
}
When i open the url i get :
Welcome to socket.io.
The connection is ok.
But, when i try to connect in my website, i get this :
GET http://myproject.com/socket.io/1/?t=1385767934694 404 (Not Found) socket.io.js:1659
this is my website line for do the connection :
var socket = io.connect('http://myproject.com/nodejs/');
How can i do that ?
I get an error =/
WebSocket connection to 'ws://myproject/socket.io/1/websocket/IomP5jiBBNv8rgGYFFUS' failed: Error during WebSocket handshake: 'Connection' header value is not 'Upgrade'
this is my nginx server side conf :
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80; ## listen for ipv4; this line is default and implied
root /home/myproject/www;
index index.html index.htm;
server_name myproject.com;
location /socket.io/ {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
if i don't add :
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
I get this error :
Restarting nginx: nginx: [emerg] unknown "connection_upgrade" variable
nginx: configuration file /etc/nginx/nginx.conf test failed
I see this conf in this link : http://mattpatenaude.com/hosting-chatroom/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With