简体   繁体   中英

How to get nginx/1.3.14 working as proxy with nodejs and socket.io

I have a nginx server serving all my static content for a webapp. The app makes use of websockets implemented in node.js unsing socket.io. The node.js Backend is listening on port 8000.

If I include the socket-io.js file via port 8000 inside the static delivered documents everything works fine but I've read something about to use nginx as a proxy handling the port 8000 internal

So I#ve build a config like these:

server {

 server_name domain.com;
 access_log /var/log/nginx/domaim.com.log;
 location / {
    root /home/app/static/;
 }

 location /socket/ {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
 }
}

Then an access to socket.io through domain.com/socket/ is possible (get the message Welcome to socket.io). Also the static content is delivered But I cant find any way to load the "socket.io/socket.io.js" file via port 80.

Is that possible on a clean way?

You could use socket.connect(url, {resource:'socket'})

The default resource is socket.io

https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM