2016-02-12 111 views
0

我一直在努力嘗試將NodeJS服務器部署爲Linode上的SocketIO服務器。我部署了可以正常工作的Django項目,並且我已將一個子域重定向到與偵聽本地主機端口8002的節點服務器進行通信。 我在我的nginx日誌中收到404錯誤。部署Nginx,Socket IO,Linode 404錯誤

"GET /socket.io/?EIO=3&transport=polling HTTP/1.1" 404 72 "-" "Dalvik/2.1.0 (Linux; U; Android 5.0.1; LG-D850 Build/LRX21Y)" 

這裏是我的nginx的配置

server { 
     listen 80; 
     server_name www.domain.com; 
     location/{ 
       proxy_pass http://127.0.0.1:8000; 
     } 
     location /static { 
       alias /home/exampledir/staticfiles; 
     } 
     access_log /home/exampledir/nginx-access.log; 
     error_log /home/exampledir/nginx-error.log info; 
} 
server { 
    listen 80; 
    server subdomain.domain.com; 
    location/{ 
     proxy_pass http://127.0.0.1:8002; 
     proxy_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection $connection_upgrade; 
    } 
} 

這裏是我的NodeJS服務器文件

var socket = require('socket.io'); 
var express = require('express'); 
var http = require('http'); 
var app = express(); 
var server = http.createServer(app); 
server.listen(8002, '127.0.0.1'); 
var io = socket.listen(server); 
var redis = require('redis'); 
var sub = redis.createClient(); 
sub.subscribe('notify'); 
io.on('connection', function(socket){ 
    socket.on('join', function (data) { 
     ... 
    }); 
}); 
//Grab message from Redis and send to client 
sub.on('message', function(channel, message){ 
... 
}); 

我一直在使用CORS和東西嘗試,但它不工作只是不斷給我一個404。我已經驗證節點服務器運行在127.0.0.1:8002 我的androi d插座正在連接到

mSocket = IO.socket("http://subdomain.domain.com/); 

請幫忙。

+0

您已確認http://127.0.0.1:8002/socket.io應用程序服務器上回來的預期?你有沒有測試一個完整的WebSocket協商直接到NodeJS端口的方法?如果您使用https://www.nginx.com/blog/websocket-nginx/中的示例,是否已爲$ connection_upgrade設置變量映射? –

回答

1

試試這個配置

server { 

    listen 80; 

    # Make site accessible from http://localhost/ 

    server_name domain.com; 

    location/{ 

      proxy_pass http://127.0.0.1:8000; 

    } 


    location/{ 

      proxy_pass http://127.0.0.1:8000; 

    } 

    location /static { 

      alias /home/example-dir/staticfiles; 

    } 

    access_log /home/example-dir/nginx-access.log; 

    error_log /home/example-dir/nginx-error.log info; 

    } 



server { 

    listen 80; 

    server_name subdomain.domain.com; 

    location/{ 

      proxy_pass http://127.0.0.1:8002; 

      proxy_http_version 1.1; 

      proxy_set_header Upgrade $http_upgrade; 

      proxy_set_header Connection "upgrade"; 

      proxy_set_header Host $host; 

    } 

    access_log /home/example-dir/socketnginx-access.log; 

    error_log /home/example-dir/socketnginx-error.log info; 

    }