Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx set up nodejs in port 80

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 ?

like image 631
Paul T. Avatar asked Oct 21 '25 16:10

Paul T.


1 Answers

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/

like image 149
Paul T. Avatar answered Oct 24 '25 07:10

Paul T.